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 times.
The score of a player is the sum of the values of the highest 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 , , , , and — the values Alice gets in her dice rolls, followed by the values which Bob gets in his 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 tie
, TIE
, Tie
, and tIe
are considered identical.
Constraints
Sample 1:
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 : Alice's score is which is greater than Bob's score .
Test Case : Alice's score is which is less than Bob's score .
Test Case : Alice's score is which is same as Bob's score .
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
Sample 1:
2 5 12 4 5
7 3
Explanation:
Test case : Om has to get a minimum of votes to ensure a strict majority win. If he gets votes, it is not possible for any other nominee to get at least votes.
Test case : Om has to get a minimum of votes to ensure a strict majority win. If he gets votes, it is not possible for any other nominee to get at least 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
3 2 5 6 1 1
4 4 5 6 4 1
6 6 6 6 6 1
Output
Bob
Tie
Demonstration
CodeChef solution DICEGAME2 - Best of Two Codechef solution in C,C++