Codeforces Three Parts of the Array 1006C Codeforces Round #498 (Div. 3)


A solution in c++

#include<bits/stdc++.h>

using namespace std;

/// Typedef
typedef long long int ll;

#define FastIO  ios_base::sync_with_stdio(false); cin.tie(0);
#define sc1(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld %lld",&a,&b)
#define sc3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)


int main()
{
    FastIO;
    ll n,m,t,c,i,j=0,k,ck=0,dk=0,a,b;

    sc1(n);
    ll arr[n];

    for(i=0; i<n; i++){
        sc1(arr[i]);
    }
    a = n-1;
    for(i=0; i<=a; ){
        if(ck<=dk) ck+=arr[i++];
        else dk+=arr[a--];
        if(ck==dk) j = ck;
    }

    cout<<j<<endl;

}

Post a Comment

0 Comments