牛客网题目链接
注意
虽然题目说了数据在长整形范围内,但是实际数据只在整型范围。
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long LL;
int main(){
int n, x;
while(cin>>n){
int sum = 0, res;
for(int i = 0; i < n; i++){
cin>>x;
sum = sum <= 0? x: sum+x;
if(i == 0) res = sum;
else res = max(res, sum);
}
cout<<res<<endl;
}
return 0;
}