Created
December 1, 2019 09:45
-
-
Save mk6619/c0039d25b6c21b7edc1f9abdd05a522c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| int main() { | |
| //code | |
| int testCases; | |
| cin>>testCases; | |
| for(int i = 0; i < testCases; i++) { | |
| int n; | |
| cin>>n; | |
| int arr[n]; | |
| for(int j=0;j<n;j++){ | |
| cin>>arr[j]; | |
| } | |
| int max_now = arr[0], max_total = arr[0]; | |
| int right =1; | |
| while(right < n) { | |
| if(arr[right] + max_now > arr[right]) { | |
| max_now = arr[right] + max_now; | |
| } else { | |
| max_now = arr[right]; | |
| } | |
| if(max_total < max_now) { | |
| max_total = max_now; | |
| } | |
| right++; | |
| } | |
| cout<<max_total<<"\n"; | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment