Created
October 25, 2012 21:50
-
-
Save itsPG/3955664 to your computer and use it in GitHub Desktop.
max winning streak by PG @ SENSE Lab
This file contains 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
/* | |
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