Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
717 B
32
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;
    int arr[n];
    for(int i=0; i<n;i++){
        cin>>arr[i];
    }

    int index[n];

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

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

    cout<<max;


    return 0;
}