我考虑问题总是不全面:
通过无限大哥提供的数据,给程序打了个“补丁”ac了,谢谢啦
#include <iostream>
using namespace std;
int main()
{
int n;
while (cin >> n && n != -1)
{
int *a = new[n+1];
for (int i = 0;i <= n;i ++)
a[i] = 0;
int uzero = 0;
int max = -999999;
for (int k = 1;k <= n;k ++)
{
cin >> a[k];
if (a[k] < 0)
{
uzero ++;
if (a[k] > max)
max = a[k];
}
}
int sum = 0;
int b = 0;
if (uzero == n)
cout << max <<endl;
else
{
for (int i = 1;i <= n;i ++)
{
if (b > 0) b += a[i];
else b = a[i];
if (b > sum) sum = b;
}
cout << sum << endl;
}
}
}