Kyrylo Kozhumyaka
Limits: 2 sec., 256 MiB
This statement was translated automatically from Ukrainian.
Once upon a time, a dreadful Dragon settled near Lviv. And every year the Dragon collected a tribute: he took one young man or woman. The brave young man Kyrylo Kozhumyaka could not tolerate this and went to the Dragon to save his people.
– Did you come to fight me? — said the Dragon.
– Of course not. Am I foolish to fight you! — Kyrylo confidently replied.
So they decided to play a game: if the young man wins, the Dragon will no longer take his tribute. In total, the Dragon has \(n\) sticks, and the \(i\)-th stick has a length of \(a_i\). Kyrylo and the Dragon take turns drawing sticks. Kyrylo draws first, then the Dragon, and then Kyrylo again, meaning they draw a total of 3 sticks. Kyrylo wins this difficult game if a non-degenerate triangle cannot be formed from these 3 sticks.
Now Kyrylo is wondering if he can win this game if on his first move he takes the \(i\)-th stick, and the Dragon acts optimally.
Input
The first line contains a single integer \(n\). The next line contains \(n\) integers \(a_i\).
Output
Output \(n\) lines. In the \(i\)-th line, output
Good job, Kyrylo! if Kyrylo can defeat the Dragon by taking
the \(i\)-th stick on his first move,
and Bon appetit, Dragon! if the evil Dragon wins.
Constraints
28% of tests: \(3 \le n \le 100, 1 \le a_i \le 10^9\),
32% of tests: \(3 \le n \le 2\cdot10^3, 1 \le a_i \le 10^9\),
40% of tests: \(3 \le n \le 10^5, 1 \le a_i \le 10^9\).
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 7 4 2 7 4 5 7 9 | Good job, Kyrylo! Good job, Kyrylo! Bon appetit, Dragon! Good job, Kyrylo! Good job, Kyrylo! Bon appetit, Dragon! Good job, Kyrylo! |
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
Kyrylo Kozhumyaka - Editorial
If Kyrylo took a stick of length \(a_i\) with his first move, the Serpent must take a stick of length \(a_j\) such that, whatever third stick of length \(a_k\) Kyrylo chooses, they make a non-degenerate triangle. For all \(k \ne i, k \ne j\) the triangle inequalities must hold: \(a_i < a_j + a_k, a_j < a_k + a_i, a_k < a_i + a_j\). Rewrite them as: \[a_j > a_i - a_k, a_j > a_k - a_i, a_j < a_k + a_i.\]
Let the shortest stick other than the \(i\)-th one have length \(a_{min}\), and the longest one \(a_{max}\). Check whether there is \(j\) such that \[a_j > a_i - a_{min}, a_j > a_{max} - a_i, a_j < a_{min} + a_i.\] If there is, this \(j\) is a winning move for the Serpent.
The inequalities \((1)\) must hold for \(k \ne j\), but our check does not ensure this and uses the stronger condition \((2)\). We can simply check separately whether the Serpent wins by taking the stick \(a_{min}\) or \(a_{max}\).
However, one can show that these extra checks are not needed. For this it is enough to prove the following two lemmas.
If the Serpent can win by taking the stick \(a_{min}\), he can win by taking the stick \(a_{max}\).
If the Serpent can win by taking the stick \(a_{max}\), the inequalities \((2)\) hold for it.
The proof is left as an exercise.
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|