Answers for "Codeforce 655 D"

0

Codeforce 655 D

#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
    ll int n; cin>>n;
    ll int a[2*n+1], sum=0;
    for(ll int i=1; i<=n; i++) cin>>a[i];
    for(ll int i=1; i<=n; i++) a[n+i]=a[i];

    for(ll int i=1; i<=n; i+=2) sum+=a[i];
    ll int ans = sum;

    for( ll int i=2; i<=2*n; i+=2){
        sum-=a[i-1];
        sum+=a[i];
        ans= max(ans, sum);
    }    
    cout<<ans<<endl;
    return 0;
}
Posted by: Guest on July-14-2020

Browse Popular Code Answers by Language