Skip to content

Instantly share code, notes, and snippets.

@mk6619
Created December 1, 2019 09:45
Show Gist options
  • Select an option

  • Save mk6619/c0039d25b6c21b7edc1f9abdd05a522c to your computer and use it in GitHub Desktop.

Select an option

Save mk6619/c0039d25b6c21b7edc1f9abdd05a522c to your computer and use it in GitHub Desktop.
#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