Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_DEPRECATE
- #include <iostream>
- #include <vector>
- #include <string>
- #include <map>
- #include <set>
- #include <algorithm>
- #define ull unsigned long long
- #define ll long long
- using namespace std;
- ll a[100001];
- ll d[100001];
- int main() {
- //freopen("input.txt", "r", stdin);
- //freopen("output.txt", "w", stdout);
- int n;
- cin >> n;
- for (int i = 0; i < n; i++) {
- cin >> a[i];
- }
- d[0] = a[0];
- d[1] = a[1];
- ll mx = max(a[0], 0ll);
- for (int i = 2; i < n; i++) {
- d[i] = a[i] + mx;
- mx = max(mx, d[i - 1]);
- }
- mx = max(mx, d[n - 1]);
- cout << mx;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment