Skip to content

Instantly share code, notes, and snippets.

@itsPG
Created October 25, 2012 21:50
Show Gist options
  • Save itsPG/3955664 to your computer and use it in GitHub Desktop.
Save itsPG/3955664 to your computer and use it in GitHub Desktop.
max winning streak by PG @ SENSE Lab
/*
max winning streak
by PG @ SENSE Lab
sample input:
3
-1 -1 -1
5
1 2 -4 2 0
27
1 1 2 -2 -1 2 -1 3 4 -1 -2 3 2 -2 10 -6 -1 2 3 3 -2 2 1 -20 11 14 -2
0
sample output:
0
3
26
*/
#include <iostream>
using namespace std;
int main()
{
int qmax;
while (cin >> qmax && qmax)
{
int min = 0, sum = 0, tmp, ans = -2147483647;
for (int i = 0; i < qmax; i++)
{
cin >> tmp;
sum += tmp;
if (sum < min) min = sum;
if (sum - min > ans) ans = sum - min;
}
cout << ans << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment