Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
566 B
0
Indexable
Never
#include <iostream>
#include <climits>

using namespace std;

typedef long long ll;

int n, a[1000001];
ll m = INT_MIN;

ll max(ll a, ll b){
    if(a > b) return a;
    return b;
}

int main(){ // O(n^2) DAYCON
    freopen("DAYCON.INP","r",stdin);
    freopen("DAYCON.OUT","w",stdout);

    cin >> n; for(int i = 1; i <= n; i++) cin >> a[i];

    a[0] = 0;
    for(int i = 1; i <= n; i++) a[i] = a[i-1] + a[i];

    for(int i = 1; i <= n; i++){
        for(int j = 0; j < i; j++)
            m = max(m, a[i] - a[j]);
    }
    cout << m << endl;
    
    return 0;
}
Leave a Comment