Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define all(x) x.begin(), x.end()
- #define ll long long
- #define ld long double
- #define pb push_back
- #define endl '\n'
- #define ff first
- #define mp make_pair
- #define ss second
- #define ull unsigned long long
- #define YES cout << "YES" << endl;
- #define NO cout << "NO" << endl;
- #define ulongmax 18446744073709551615
- #define pll pair<ll,ll>
- using namespace std;
- ll maxn = -1e9;
- ll minn = 1e9;
- ll mod = 1e9 + 7;
- const int maxx = 3e6 + 5;
- const int base = 311;
- ll a[maxx];
- int main(){
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- //freopen("HACK.TXT","r",stdin);
- //freopen(".INP","r",stdin);
- //freopen(".OUT","w",stdout);
- //freopen("HACK.TXT","w",stdout);
- ll n;
- cin >> n;
- for (int i = 1; i <= n; i++){
- cin >> a[i];
- }
- ll mn = 0;
- ll ans = 0;
- ll tong = 0;
- for (int i = 1; i <= n; i++){
- tong = tong + a[i];
- mn = mn + a[i];
- if (mn > 0) mn = 0;
- if (mn < ans) ans = mn;
- }
- cout << (-ans) * 2 + tong;
- }
- /*
- 5 2
- 1 2
- 2 3
- 3 4
- 1 5
- 5 2
- 4 1
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement