Advertisement
STANAANDREY

ssm(sume part)

Nov 18th, 2020
589
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.     //freopen("text.txt", "r", stdin);
  6.     int n, a[103] = {}, sp[103] = {};
  7.     cin >> n;//min 1 nr > 0
  8.     assert(n <= 100);
  9.     for (int i = 1; i <= n; i++) {
  10.         cin >> a[i];
  11.         sp[i] = sp[i - 1] + a[i];
  12.         assert(abs(a[i]) < 100000);
  13.     }
  14.     int mini = 0, ans = -1e9;
  15.     for (int i = 1; i <= n; i++) {
  16.         ans = max(ans, sp[i] - mini);
  17.         mini = min(mini, sp[i]);
  18.     }
  19.     cout << ans << endl;
  20.     return 0;
  21. }
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement