Codeforces Round #693 (Div. 3) 1472D - Even-Odd Game Solution



 Problem Link: https:   https://codeforces.com/contest/1472/problem/D

Solution in C++:

///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat  Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long n,t,i,sa,sb;
    cin>>t;
    while(t--)
    {
        sa=sb=0;
        cin>>n;
        long long a[n+9];
        for(i=1; i<=n; i++)
        {
            cin>>a[i];
        }
        sort(a+1,a+n+1);
        for(i=n; i>=1; i=i-2)
        {
            if(a[i]%2==0)
                sa+=a[i];
        }
        for(i=n-1; i>=1; i=i-2)
        {
            if(a[i]%2==1)
                sb+=a[i];
        }
        if(sa>sb)
            cout<<"Alice"<<endl;
        else if(sa<sb)
            cout<<"Bob"<<endl;
        else
            cout<<"Tie"<<endl;
    }
}

 

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

Powered by Blogger.