Algorithm


 problem Link :  https://www.codechef.com/START97D/problems/DICEGAME2 

Problem

Alice and Bob are playing a game. Each player rolls a regular six faced dice 3 times.
The score of a player is the sum of the values of the highest 2 rolls. The player with the highest score wins, and the game ends in a Tie if both players have the same score.

Find the winner of the game or determine whether it is a tie.

Input Format

  • The first line of input will contain a single integer , denoting the number of test cases.
  • Each test case contains six space-separated integers �1�2�3�1�2 and �3 — the values Alice gets in her 3 dice rolls, followed by the values which Bob gets in his 3 dice rolls.

Output Format

For each test case, output on a new line Alice if Alice wins, Bob if Bob wins and Tie in case of a tie.

Note that you may print each character in uppercase or lowercase. For example, the strings tieTIETie, and tIe are considered identical.

Constraints

  • 1≤�≤104
  • 1≤�1,�2,�3,�1,�2,�3≤6

Sample 1:

Input
 
Output
 
3
3 2 5 6 1 1
4 4 5 6 4 1
6 6 6 6 6 1
Alice
Bob
Tie

Explanation:

Test Case 1: Alice's score is 8=(3+5) which is greater than Bob's score 7=(6+1).

Test Case 2: Alice's score is 9=(5+4) which is less than Bob's score 10=(6+4).

Test Case 3: Alice's score is 12=(6+6) which is same as Bob's score 12=(6+6).

Problem

In the Gymkhana elections of IIIT-A,  members are nominated for senator positions. The total number of voters in the college is .

Om, one of the  nominees, wants to secure a strict majority win in the election.

Assuming all voters cast their votes, find the minimum number of votes Om requires to ensure a strict majority win.

Note that in a strict majority win, all the nominees have strictly lesser votes than the winner.

Input Format

  • The first line of input will contain a single integer , denoting the number of test cases.
  • Each test case consists of two space-separated integers  and  — the number of nominated members and the number of voters respectively.

Output Format

For each test case, output the minimum number of votes Om requires to ensure a strict majority win.

Constraints

  • 1≤�≤105
  • 2≤�≤�≤109

Sample 1:

Input
 
Output
 
2
5 12 
4 5 
7
3

Explanation:

Test case 1: Om has to get a minimum of 7 votes to ensure a strict majority win. If he gets 7 votes, it is not possible for any other nominee to get at least 7 votes.

Test case 2: Om has to get a minimum of 3 votes to ensure a strict majority win. If he gets 3 votes, it is not possible for any other nominee to get at least 3 votes.

Code Examples

#1 Code Example with C Programming

Code - C Programming

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


void solve()
{
    vector<int>a;
    vector<int>b;
    for(int i=0; i < 3; i++)
    {
        int x;
        cin>>x;
        a.push_back(x);
    }
    for(int i=0; i < 3; i++)
    {
        int x;
        cin>>x;
        b.push_back(x);
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());

    int alice=accumulate(a.begin()+1,a.end(),0);
    int bob=accumulate(b.begin()+1,b.end(),0);

    if(alice>bob) cout<<"Alice"<<endl;
    else if(bob>alice) cout<<"Bob"<<endl;
    else cout<<"Tie"<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int TC = 1;
    cin >> TC;
    cin.ignore();
    while (TC--) solve();
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
3
3 2 5 6 1 1
4 4 5 6 4 1
6 6 6 6 6 1

Output

x
+
cmd
Alice
Bob
Tie
Advertisements

Demonstration


CodeChef solution DICEGAME2  - Best of Two Codechef solution  in C,C++

Previous
CodeChef solution CS2023_STK - CodeChef Streak Codechef solution in C,C++
Next
CodeChef solution CHN15A - Mutated Minions Codechef solution in C,C++