DICENUM - Editorial

PROBLEM LINK:

Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4

Author: notsoloud
Tester: raysh07
Editorialist: iceknight1093

DIFFICULTY:

TBD

PREREQUISITES:

None

PROBLEM:

Alice and Bob roll three dice. The score of a player is the maximum number that can be formed from the digits they have.
Find the person with higher score.

EXPLANATION:

The largest number Alice can form is by placing \max(A_1, A_2, A_3) first; then the maximum of the remaining two digits next; and finally the last one.
This can also be seen as sorting the array [A_1, A_2, A_3] in descending order.

Bob’s largest number is similarly obtained by sorting [B_1, B_2, B_3] in descending order.

Once both players’ scores are known, compare them to see who wins, for example by using if conditions.

TIME COMPLEXITY

\mathcal{O}(1) per testcase.

CODE:

Editorialist's code (Python)
for _ in range(int(input())):
    a, b, c, d, e, f = map(int, input().split())
    alice, bob = sorted([a, b, c]), sorted([d, e, f])
    ans = 'Tie'
    for i in reversed(range(3)):
        if alice[i] == bob[i]: continue
        if alice[i] < bob[i]: ans = 'Bob'
        else: ans = 'Alice'
        break
    print(ans)