#C10882. Dragon Selection Strategy
Dragon Selection Strategy
Dragon Selection Strategy
In this problem, you are given two teams that select dragons from a pool of (2k) dragons, each with an associated power value. The powers are provided in ascending order of their indices (which are 1-indexed). Depending on whether your team picks first or second, you need to choose the best remaining dragon based on the following strategy:
- If your team picks first (turn = 1), simply select the dragon with the highest index (i.e. the dragon with the maximum power).
- If your team picks second (turn = 2), the opponent makes a move first. After reading the opponent's choice from standard input, select the highest-indexed dragon that is still available. Note that if the opponent has taken the dragon with the highest index, you should pick the next highest one.
Formally, let (k) be the number of dragons per team so that the total number of dragons is (2k). If the opponent's move (when applicable) is represented by an integer (d) and (d = 2k), then your answer should be (2k - 1); otherwise, your answer is (2k).
This problem tests your ability to apply a simple greedy strategy and handle input/output via standard streams. Good luck!
inputFormat
The input is given via standard input in the following format:
Line 1: A single integer (k), representing the number of dragons per team. Line 2: (2k) space-separated integers representing the power values of the dragons (in ascending order by index). Line 3: A single integer representing the turn (1 if your team picks first, 2 if the opponent picks first). Line 4 (only if turn = 2): A single integer representing the opponent's chosen dragon index.
outputFormat
Output a single integer --- the index of the dragon selected by your team.## sample
4
5 10 15 20 25 30 35 40
1
8