codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1056C.md (4575B)


      1 Source: https://codeforces.com/problemset/problem/1056/C
      2 
      3 C. Pick Heroes
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Don't you tell me what you think that I can be
     22 
     23 If you say that Arkady is a bit old-fashioned playing checkers, you won't be right. There is also a modern computer game Arkady and his friends are keen on. We won't discuss its rules, the only feature important to this problem is that each player has to pick a distinct hero in the beginning of the game.
     24 
     25 There are $2$ teams each having $n$ players and $2n$ heroes to distribute between the teams. The teams take turns picking heroes: at first, the first team chooses a hero in its team, after that the second team chooses a hero and so on. Note that after a hero is chosen it becomes unavailable to both teams.
     26 
     27 The friends estimate the power of the $i$-th of the heroes as $p_i$. Each team wants to maximize the total power of its heroes. However, there is one exception: there are $m$ pairs of heroes that are especially strong against each other, so when any team chooses a hero from such a pair, the other team must choose the other one on its turn. Each hero is in at most one such pair.
     28 
     29 This is an interactive problem. You are to write a program that will optimally choose the heroes for one team, while the jury's program will play for the other team. Note that the jury's program may behave inefficiently, in this case you have to take the opportunity and still maximize the total power of your team. Formally, if you ever have chance to reach the total power of $q$ or greater regardless of jury's program choices, you must get $q$ or greater to pass a test.
     30 
     31 Input
     32 
     33 The first line contains two integers $n$ and $m$ ($1 \le n \le 10^3$, $0 \le m \le n$) — the number of players in one team and the number of special pairs of heroes.
     34 
     35 The second line contains $2n$ integers $p_1, p_2, \ldots, p_{2n}$ ($1 \le p_i \le 10^3$) — the powers of the heroes.
     36 
     37 Each of the next $m$ lines contains two integer $a$ and $b$ ($1 \le a, b \le 2n$, $a \ne b$) — a pair of heroes that are especially strong against each other. It is guaranteed that each hero appears at most once in this list.
     38 
     39 The next line contains a single integer $t$ ($1 \le t \le 2$) — the team you are to play for. If $t = 1$, the first turn is yours, otherwise you have the second turn.
     40 
     41 Hacks
     42 
     43 In order to hack, use the format described above with one additional line. In this line output $2n$ distinct integers from $1$ to $2n$ — the priority order for the jury's team. The jury's team will on each turn select the first possible hero from this list. Here possible means that it is not yet taken and does not contradict the rules about special pair of heroes.
     44 
     45 Interaction
     46 
     47 When it is your turn, print a single integer $x$ ($1 \le x \le 2n$) — the index of the hero chosen by you. Note that you can't choose a hero previously chosen by either you of the other player, and you must follow the rules about special pairs of heroes.
     48 
     49 When it is the other team's turn, read a line containing a single integer $x$ ($1 \le x \le 2n$) — the index of the hero chosen by the other team. It is guaranteed that this index is not chosen before and that the other team also follows the rules about special pairs of heroes.
     50 
     51 After the last turn you should terminate without printing anything.
     52 
     53 After printing your choice do not forget to output end of line and flush the output. Otherwise you will get Idleness limit exceeded. To do this, use:
     54 
     55 * fflush(stdout) or cout.flush() in C++;
     56 * System.out.flush() in Java;
     57 * flush(output) in Pascal;
     58 * stdout.flush() in Python;
     59 * see documentation for other languages.
     60 
     61 Jury's answer $-1$ instead of a valid choice means that you made an invalid turn. Exit immediately after receiving $-1$ and you will see Wrong answer verdict. Otherwise you can get an arbitrary verdict because your solution will continue to read from a closed stream.
     62 
     63 Examples
     64 
     65 Input
     66 
     67 ```
     68 3 1
     69 1 2 3 4 5 6
     70 2 6
     71 1
     72 
     73 2
     74 
     75 4
     76 
     77 1
     78 ```
     79 
     80 Output
     81 
     82 ```
     83 6
     84 
     85 5
     86 
     87 3
     88 ```
     89 
     90 Input
     91 
     92 ```
     93 3 1
     94 1 2 3 4 5 6
     95 1 5
     96 2
     97 6
     98 
     99 1
    100 
    101 3
    102 ```
    103 
    104 Output
    105 
    106 ```
    107 5
    108 
    109 4
    110 
    111 2
    112 ```
    113 
    114 Note
    115 
    116 In the first example the first turn is yours. In example, you choose $6$, the other team is forced to reply with $2$. You choose $5$, the other team chooses $4$. Finally, you choose $3$ and the other team choose $1$.
    117 
    118 In the second example you have the second turn. The other team chooses $6$, you choose $5$, forcing the other team to choose $1$. Now you choose $4$, the other team chooses $3$ and you choose $2$.