Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Chef is the judge of a competition. There are two players participating in this competition — Alice and Bob.
The competition consists of N races. For each i (1 ≤ i ≤ N), Alice finished the i-th race in Ai minutes, while Bob finished it in Bi minutes. The player with the smallest sum of finish times wins. If this total time is the same for Alice and for Bob, a draw is declared.
The rules of the competition allow each player to choose a race which will not be counted towards their total time. That is, Alice may choose an index x and her finish time in the race with this index will be considered zero; similarly, Bob may choose an index y and his finish time in the race with this index will be considered zero. Note that x can be different from y; the index chosen by Alice does not affect Bob’s total time or vice versa.
Chef, as the judge, needs to announce the result of the competition. He knows that both Alice and Bob play optimally and will always choose the best option. Please help Chef determine the result!
For each test case, print a single line containing the string “Alice” if Alice wins, “Bob” if Bob wins or “Draw” if the result is a draw (without quotes).
Input:
3
5
3 1 3 3 4
1 6 2 5 3
5
1 6 2 5 3
3 1 3 3 4
3
4 1 3
2 2 7
Output:
Alice
Bob
Draw
Example case 1: Alice will choose the finish time in the last race to be considered zero, which means her sum of finish times is 3 + 1 + 3 + 3 + 0 = 10, while Bob will choose the finish time of his second race to be considered zero, so his total sum of finish times is 1 + 0 + 2 + 5 + 3 = 11. Since Alice’s sum is smaller, she is considered the winner.
Example case 2: We’re dealing with the same situation as in the previous case, but finish times for the players are swapped, so Bob wins this time.
Example case 3: Alice will choose the finish time of the first race to be considered zero, which means her total time is 0 + 1 + 3 = 4. Bob will choose the finish time of his last race to be considered zero, which makes his total time 2 + 2 + 0 = 4. The competition is considered a draw because both players have equal sums of finish times.
# cook your dish here
for i in range(int(input())):
a=int(input())
b=list(map(int,input().split()))
c=list(map(int,input().split()))
d=max(b)
e=max(c)
b.remove(d)
c.remove(e)
x=sum(b)
y=sum(c)
if x<y:
print("Alice")
elif x>y:
print("Bob")
else:
print("Draw")
#include <iostream>
using namespace std;
void removeMax(int arr[], int n){
int max = arr[0];
for(int i = 1; i < n; i++){
if(max < arr[i]){
max = arr[i];
}
}
for(int i = 0; i < n; i++){
if(arr[i] == max){
arr[i] = 0;
break;
}
}
}
int sumArr(int arr[], int n){
int sum = 0;
for(int i = 0; i < n; i++){
sum += arr[i];
}
return sum;
}
int main() {
int t; cin >> t;
while(t--){
int n; cin >> n;
int a[n],b[n];
for(int i = 0; i < n; i++){
cin >> a[i];
}
for(int i = 0; i < n; i++){
cin >> b[i];
}
removeMax(a,n);
removeMax(b,n);
if(sumArr(a,n) < sumArr(b,n)){
cout << "Alice" << endl;
}
else if(sumArr(a,n) == sumArr(b,n)){
cout << "Draw" << endl;
}
else if(sumArr(a,n) > sumArr(b,n)){
cout << "Bob" << endl;
}
}
return 0;
}
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
int m1=0;
int m2=0;
int sum=0;
int sum1=0;
int arr[]=new int[n];
int arr1[]=new int[n];
for(int i=0;i<n;i++){
arr[i]=sc.nextInt();
sum=sum+arr[i];
if(arr[i]>m1){
m1=arr[i];
}
}
for(int i=0;i<n;i++){
arr1[i]=sc.nextInt();
sum1=sum1+arr1[i];
if(arr1[i]>m2){
m2=arr1[i];
}
}
sum-=m1;
sum1-=m2;
if(sum==sum1){
System.out.println("Draw");
}else if(sum>sum1){
System.out.println("Bob");
}else{
System.out.println("Alice");
}
}
}
}
In our experience, we suggest you solve this Chef Judges a Competition CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.
If you are stuck anywhere between any coding problem, just visit Queslers to get the Lucky Four CodeChef Solution
I hope this Chef Judges a Competition CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.
This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.
Keep Learning!
More Coding Solutions >>