304 North Cardinal St.
Dorchester Center, MA 02124

# Chef Judges a Competition CodeChef Solution

## Problem – Chef Judges a Competition CodeChef Solution

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!

### Input

• The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
• The first line of each test case contains a single integer N.
• The second line contains N space-separated integers A1, A2, …, AN.
• The third line contains N space-separated integers B1, B2, …, BN.

### Output

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).

### Constraints

• 1 ≤ T ≤ 100
• 2 ≤ N ≤ 100
• 1 ≤ Ai ≤ 1000 for each valid i
• 1 ≤ Bi ≤ 1000 for each valid i

### Sample 1:

``````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``````

### Explanation:

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.

## Chef Judges a Competition CodeChef Solution in Pyth 3

``````# 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")``````

## Chef Judges a Competition CodeChef Solution in C++14

``````#include <iostream>
using namespace std;

void removeMax(int arr[], int n){
int max = arr;
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;
}
``````

## Chef Judges a Competition CodeChef Solution in Java

``````/* 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
{
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");
}
}
}
}
``````
##### Chef Judges a Competition CodeChef Solution Review:

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

Find on CodeChef

##### Conclusion:

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 >>

LeetCode Solutions

Hacker Rank Solutions

CodeChef Solutions