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

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

Sample Output 1 

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 JAVA

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();
        for(int i =0;i<t;i++){
            int g = sc.nextInt();
            int[] alice = new int[g];
            int[] bob = new int[g];
            for(int j = 0 ;j<g;j++){
                alice[j]=sc.nextInt();
            }
            for(int j = 0;j<g;j++){
                bob[j]=sc.nextInt();
            }
            Arrays.sort(alice);
            Arrays.sort(bob);
            alice[g-1] =0;
            bob[g-1] = 0;
            int alicevar = 0;
            int bobvar = 0;
            for(int j: alice){
                alicevar=alicevar+j;
            } for(int j: bob){
                bobvar=bobvar+j;
            }
            if(alicevar > bobvar){
                System.out.println("Bob");
            }else if(alicevar<bobvar){
                System.out.println("Alice");
            }else{
                System.out.println("Draw");
            }
        }
	}
}

Chef Judges a Competition- CodeChef Solution in CPP

#include <iostream>
using namespace std;

int main() {
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int ar[n],arr[n];
        int sum=0,max=0,sum1=0,maxi=0;
        for(int i=0;i<n;i++){
            cin>>ar[i];
            if(max<ar[i]){
                max=ar[i];
            }
        }
        for(int i=0;i<n;i++){
            sum=sum+ar[i];
        }
        int a=sum-max;
        for(int i=0;i<n;i++){
            cin>>arr[i];
            if(maxi<arr[i]){
                maxi=arr[i];
            }
        }
        for(int i=0;i<n;i++){
            sum1=sum1+arr[i];
        }
        int b=sum1-maxi;
        if(a<b)
            cout<<"Alice\n";
        else if(a==b)
            cout<<"Draw\n";
        else if(a>b)
            cout<<"Bob\n";
        }
	return 0;
}

Chef Judges a Competition -CodeChef Solution in Python

for _ in range(int(input())):
    n = int(input())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    a.remove(max(a))
    b.remove(max(b))
    a = sum(a)
    b = sum(b)
    if(a<b):
        print("Alice")
    elif(b<a):
        print("Bob")
    else :
        print("Draw")

Disclaimer: The above Problem (Chef Judges a Competition) is generated by CodeChef but the solution is provided by Codeworld19.This tutorial is only for Educational and Learning purpose.

Leave a Reply

Your email address will not be published. Required fields are marked *