Codeforces Round #640 (Div. 4) 1352D - Alice, Bob and Candies Solution


 

Problem Link: https://codeforces.com/problemset/problem/1352/D

Solution in C++:

///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat  Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
///**********ALLAH IS ALMIGHTY************///
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t,i,j,o,sa,sb,n,a,b,cn;
    cin>>t;
    while(t--)
    {
        a=b=cn=sa=sb=0;
        cin>>n;
        int ar[n];
        for(i=1; i<=n; i++)cin>>ar[i];
        for(i=1,j=n; i<=j;)
        {
            if(i<=j)
                cn++,a=0;
            while(i<=j&&a<=b)
                sa+=ar[i],a+=ar[i],i++;
            if(i<=j)
                cn++,b=0;
            while(i<=j&&b<=a)
                sb+=ar[j],b+=ar[j],j--;
        }
        cout<<cn<<" "<<sa<<" "<<sb<<endl;
    }
}


 

No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.