Throwing dice#11753

Throwing dice (Editorial)

Expected value of one die. A die with sides shows each of the faces 1, 2, ..., s with probability , so its expected value is the arithmetic mean of these numbers:

E = \frac{1 + 2 + ... + s}{s} = \frac{1+s}{2}.

The expected value of a sum equals the sum of the expected values, so for Alice's score and Bob's score

E[A] = \frac{(a_1 + 1)+ ... + (a_m + 1)}{2},~~~E[B] = \frac{(b_1 + 1) + ... + (b_n + 1)}{2}

The scores are distributed symmetrically about their expected values. On a single die, the values and , and s - 1, and so on, occur with equal probability, so the die is symmetric about (1 + s) / 2. A sum of symmetric random variables is also symmetric about its expected value.

Alice has the advantage if E[A] > E[B], and Bob has it if E[A] < E[B]. Therefore,

p_a > p_b ⇔ E[A] > E[B] ⇔ \\ a_1 + a_2 + ... + a_m + m > b_1 + b_2 + ... +b_n + n.

To solve the problem, it is enough to compare the sums SA = \sum a_k + m and SB = \sum b_k + n.

Example

Alice has eight dice with sides, and Bob has one die with sides. Then SA = 8 \cdot 4 + 8 = 40 and SB = 6 + 1 = 7, so SA > SB, and the answer is ALICE.

Let us verify this directly. The smallest sum Alice can get is 8 \cdot 1 = 8, while Bob's largest sum is . Therefore Alice wins for every outcome of the rolls: p_a = 1, p_b = 0.

Consider the second test. Alice has dice with and sides, and Bob has dice with and sides. Then SA = 6 + 4 + 2 = 12 and SB = 4 + 6 + 2 = 12, so SA = SB, and the answer is TIED.

This is clear even without any computation: Alice and Bob have the same sets of dice, only listed in a different order. Therefore their scores have the same distribution, and p_a = p_b.

Algorithm implementation

Read the input data. Accumulate the sum \sum a_k + m in the variable , and the sum \sum b_k + n in the variable .

scanf("%d %d", &m, &n);
sA = m;  sB = n;
for (i = 0; i < m; i++)
{
  scanf("%d", &x);
  sA += x;
}

for (i = 0; i < n; i++)
{
  scanf("%d", &x);
  sB += x;
}

Compare the sums and print the answer.

if (sA > sB)
  puts("ALICE");
else if (sA < sB)
  puts("BOB");
else
  puts("TIED");