提交时间:2021-05-22 17:38:02
运行 ID: 19788
#include<bits/stdc++.h> using namespace std; int main() { int size; cin>>size; vector<int> nums(size); for(size_t i=0;i<size;++i){ cin>>nums[i]; } int result=nums[0]; int sum1=0,sum2=0; for (int i=0;i<nums.size();i++){ sum2=sum1>=0?sum1+nums[i]:nums[i]; if(sum2>result){ result=sum2; } if(sum2<0){ sum2=0; } sum1=sum2; } cout<<result<<endl; return 0; }