Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
731 B
2
Indexable
Never
#include<iostream>
using namespace std;

int last_index(int num){
    int combined = 1;
    int n = num;

    while(true){

        if(num-combined>=0){
            num-=combined;
            combined++;
        }
        else break;
    }
    return n -num;

}

int main(){

    int n;
    cin>>n;
    long arr[n];
    long pf[n+1];
    pf[0] = 0;
    for(int i=1; i<=n;i++){
        cin>>arr[i-1];
        pf[i] = pf[i-1] + arr[i-1];
    }


    long index[n];

    for(int i = 0; i<n;i++){
        index[i] = pf[i+last_index(n-i)] - pf[i];
    }

    long max = index[0];
    for(int i =1;i<n;i++){
        if(max < index[i]) max = index[i];
    }

    cout<<max;


    return 0;
}