Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- ios::sync_with_stdio(false);
- cin.tie(0);
- int n;
- cin >> n;
- vector<int> a(n);
- for (int i = 0; i < n; i++)
- cin >> a[i];
- int64_t ans = INT_MIN, sum = 0;
- for (int x : a) {
- sum += x;
- ans = max(ans, sum);
- if (sum < 0)
- sum = 0;
- }
- cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement