PROBLEM LINK:
Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4
Author: yash_daga
Tester: jay_1048576
Editorialist: iceknight1093
DIFFICULTY:
789
PREREQUISITES:
None
PROBLEM:
Alice and Bob roll 3 regular 6-sided dice each, and obtain values A_1, A_2, A_3 and B_1, B_2, B_3, respectively.
A player’s score is the sum of the maximum two values they obtain.
Find out who has a larger score.
EXPLANATION:
Let A denote Alice’s score, and B denote Bob’s score.
They can be found as follows:
A = A_1 + A_2 + A_3 - \min(A_1, A_2, A_3) \\
B = B_1 + B_2 + B_3 - \min(B_1, B_2, B_3)
The idea here is that to find the sum of the largest two values, we can instead take the sum of all three values, then remove the smallest one.
Once A and B are found, compare them using an if
condition and print Alice
, Bob
, or Tie
appropriately.
TIME COMPLEXITY
\mathcal{O}(1) per testcase.
CODE:
Editorialist's code (Python)
for _ in range(int(input())):
a1, a2, a3, b1, b2, b3 = map(int, input().split())
alice, bob = a1+a2+a3 - min(a1, a2, a3), b1+b2+b3 - min(b1, b2, b3)
print('Alice' if alice > bob else ('Bob' if alice < bob else 'Tie'))