严格注意语句顺序不能改变。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #include<iostream> #include<algorithm> using namespace std; int n; int A[200005]; int mmax = 0x80000000; int main() { ios::sync_with_stdio(false); cin >> n; for (int i = 1; i <= n; i++)cin >> A[i]; int curSum = 0; for (int i = 1; i <= n; i++) { curSum += A[i]; mmax = max(mmax, curSum); if (curSum < 0)curSum = 0; } cout << mmax; } |