1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| #include <bits/stdc++.h> using namespace std;
int data[100000]; int maxsum(int *a, int ln) { int maxi = 0, ans = 0; for (int i = 1; i <= ln; i++) { if (maxi < 0) maxi = data[i]; else maxi+=data[i]; ans = max(ans, maxi); } return ans; } int main() { int len; cin >> len; for (int i = 1; i <= len; i++) cin >> data[i]; cout << maxsum(data, len); }
|