/*
习题 32:最大数字子串之和★★
输入n(1<=n<=1e6)和n个整数,这n个整数的绝对值均小于1000,求最大数字子串之和
样例输入:
9
-3 4 9 2 -10 -7 11 3 -8
13
-1 2 6 -3 5 -7 14 -5 -15 1 8 -4 9
样例输出:
15
17
提示:
在第一组中,最大的数字子串是4 9 2的和
在第二组中,最大的数字子串是2 6 -3 5 -7 14的和
*/
样例输入:
9
-3 4 9 2 -10 -7 11 3 -8
13
-1 2 6 -3 5 -7 14 -5 -15 1 8 -4 9
样例输出:
15
17
提示:
在第一组中,最大的数字子串是4 9 2的和
在第二组中,最大的数字子串是2 6 -3 5 -7 14的和
*/
#include <iostream>
using namespace std;
int main(void)
{
int n;
int max,tmp,result;
while(EOF!=scanf("%d",&n))
{
max = 0x80000000;
result = 0;
while(n-- > 0)
{
scanf("%d",&tmp);
if(result >= 0)
result += tmp;
else
result = tmp;
if(max < result)
max = result;
}
cout << max << endl;
}
}
using namespace std;
int main(void)
{
int n;
int max,tmp,result;
while(EOF!=scanf("%d",&n))
{
max = 0x80000000;
result = 0;
while(n-- > 0)
{
scanf("%d",&tmp);
if(result >= 0)
result += tmp;
else
result = tmp;
if(max < result)
max = result;
}
cout << max << endl;
}
}
/*
http://yzfy.org/dis/goto.php?got ... d=79417&ptid=93
Name: " younthu" Problem ID " 32"
Submit Time: 2008/10/02-13:11
G++: Compile OK
Test 1: Accepted Time = 0 ms
Test 2: Accepted Time = 0 ms
Test 3: Accepted Time = 23 ms
Test 4: Accepted Time = 454 ms
Test 5: Accepted Time = 0 ms
--------------------------------
Problem ID 32
Test Result Accepted
Total Time 477 ms
Total Memory 200 Kb / 100000 Kb
Code Length 349 Bytes
*/