1472D - Even-Odd Game - CodeForces Solution


dp games greedy sortings *1200

Please click on ads to support us..

Python Code:

for i in range(int(input())):
    n = int(input())

    my_list = list(map(int,input().split()))

    my_list.sort()

    sum_Alice = 0
    sum_Bob   = 0
    j = 0
    i = n-1
    while i>=0:
        elem = my_list[i]

        if j%2:
            if elem%2:
                sum_Bob += elem
        else:
            if elem%2==0:
                sum_Alice += elem
        j += 1
        i -= 1

    if sum_Alice>sum_Bob:
        print("Alice")
    elif sum_Alice<sum_Bob:
        print("Bob")
    else:
        print("Tie")
        


C++ Code:

#include <vector>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <cmath>
#include <limits.h>
#include <unordered_set>
#define lli long long int
#define vi vector<int>
#define vvi vector<vector<int>>
using namespace std;
int main()
{
    int t;cin>>t;
    while(t--)
    {
        lli n;cin>>n;
        vector<lli>vec(n);
        lli e_sum=0,o_sum=0;
        for(lli i=0;i<n;i++)
        {
            cin>>vec[i];
        }
        sort(vec.begin(),vec.end(),greater<lli>());
        bool flag=true;
        for(lli i=0;i<n;i++)
        {
            if(flag)
            {
                flag=false;
                if(vec[i]%2==0)
                {
                    e_sum+=vec[i];
                }
            }
            else
            {
                flag=true;
                if(vec[i]%2!=0)
                {
                    o_sum+=vec[i];
                }
            }
        }
        if(e_sum>o_sum)
        {
            cout<<"Alice"<<endl;
        }
        else if(e_sum<o_sum)
        {
            cout<<"Bob"<<endl;
        }
        else{
            cout<<"Tie"<<endl;
        }
    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

1626A - Equidistant Letters
977D - Divide by three multiply by two
1654B - Prefix Removals
1654A - Maximum Cake Tastiness
1649A - Game
139A - Petr and Book
1612A - Distance
520A - Pangram
124A - The number of positions
1041A - Heist
901A - Hashing Trees
1283A - Minutes Before the New Year
1654D - Potion Brewing Class
1107B - Digital root
25A - IQ test
785A - Anton and Polyhedrons
1542B - Plus and Multiply
306A - Candies
1651C - Fault-tolerant Network
870A - Search for Pretty Integers
1174A - Ehab Fails to Be Thanos
1169A - Circle Metro
780C - Andryusha and Colored Balloons
1153A - Serval and Bus
1487C - Minimum Ties
1136A - Nastya Is Reading a Book
1353B - Two Arrays And Swaps
1490E - Accidental Victory
1335A - Candies and Two Sisters
96B - Lucky Numbers (easy)