#P9112. Arrow Shooting Tournament

    ID: 22271 Type: Default 1000ms 256MiB

Arrow Shooting Tournament

Arrow Shooting Tournament

A tournament of archery is being held. There are targets arranged in a line and numbered from $1$ to $N$. There are $2N$ contestants. At any moment, exactly two contestants stand at the same target. The tournament proceeds in $R$ rounds (with $R\ge 2N$) and each round is conducted as follows:

  • At each target, the two contestants compete. Their skills are given by distinct integers, and the contestant with the smaller number (i.e. better skill) is declared the winner.
  • After the contest, the contestants move according to these rules:
    • If a contestant is the winner and is at a target with number $i\;(2\le i\le N)$, they move to target $i-1$.
    • If a contestant is the loser and is at a target with number $i\;(2\le i\le N)$, they remain at the same target.
    • At target $1$, the winner stays, and the loser moves to target $N$.

Before the tournament begins, exactly $2N-1$ contestants (your opponents) have already lined up. You are the last to arrive, and you can insert yourself anywhere into this queue. After you join, the queue of $2N$ contestants is split into pairs from left to right: the first two contestants go to target $1$, the next two to target $2$, and so on until target $N$.

You know the skill levels of all contestants (all numbers are distinct) and the order in which your opponents stand. Your objective is two‐fold:

  1. You want the final target you end up at (after $R$ rounds) to be as small as possible.
  2. If there are multiple insertion positions that achieve the same final target, among these you want your initial target number (i.e. the target you are assigned right after the pairing) to be as large as possible.
  3. </p>

    Write a program that, given all contestants' skill levels and the ordering of your opponents, computes the initial target number you should obtain by inserting yourself optimally.

    Movement recap in one round (using 0-indexed arrays for targets):

    • Let target $1$ correspond to index $0$, target $2$ to index $1$, ..., target $N$ to index $N-1$.
    • For target $1$ (index $0$): after competition, let winner[0] and loser[0] be determined. Then target $1$ in the next round will have: [winner[0], winner[1]] (where winner[1] is from target $2$).
    • For target $i$ with $2\le i\le N-1$ (index $i-1$): it receives [loser[i-1], winner[i]].
    • For target $N$ (index $N-1$): it receives [loser[N-1], loser[0]] (since the loser at target $1$ moves to target $N$).

    Input/Output: See below.

    inputFormat

    The first line contains two integers $N$ and $R$.

    The second line contains $2N-1$ space-separated integers, representing your opponents' skill levels in the order they are standing.

    The third line contains one integer, representing your own skill level.

    outputFormat

    Output a single integer: the initial target number (between $1$ and $N$) that you will be assigned, under an optimal insertion strategy. The strategy is to minimize your final target number after $R$ rounds; if there are several ways to achieve that, choose the one in which your initial target number is maximized.

    sample

    2 2
    3 1 2
    4
    2