代码如下——
#include<iostream>
#include<limits.h>
using namespace std;
int main()
{
int n;
cin >> n;
while (n--)
{
int m,x;
int sum1, sum2;
bool f = false;
sum1 = 0, sum2 = INT_MIN;
cin >> m;
for (int i = 1; i <= m; i++)
{
cin >> x;
if (x >= 0)
{
sum1 += x;
f = true;
}
else
{
if (x > sum2)
{
sum2 = x;
}
}
}
if (f)
{
cout << sum1 << endl;
}
else
{
cout << sum2 << endl;
}
}
}
运行结果如下——