#P6294. Alice and Bob's Optimal Game
Alice and Bob's Optimal Game
Alice and Bob's Optimal Game
Alice and Bob are playing a game. They are given a sequence of n positive integers where each integer is at most n. The elements of the sequence are labeled from 1 to n (and the sequence may contain duplicate values). Initially, a multiset \(S\) is formed containing the first p elements of the sequence. Then the game begins with Alice playing first. In each move:
- The current player chooses a number from \(S\) and removes it from \(S\), adding its value to their personal score (both start with score 0).
- If there is any remaining number in the sequence, the next number (in order) is added to \(S\). Specifically, after the first removal, the \(p+1\)-th element is added; after the second removal, the \(p+2\)-th element is added; and so on.
The game continues until \(S\) becomes empty. Assuming both players play optimally (i.e. they both maximize their own advantage), the outcome of the game is defined as:
[ \text{Game Result} = \text{(Alice's score)} - \text{(Bob's score)}. ]
Your task is to compute the result of k games (all played with the same given sequence). Since the sequence is identical for every game, the result will be the same for each game.
inputFormat
The input consists of two lines.
The first line contains three integers \(n\), \(p\) and \(k\) (with \(1 \leq p \leq n\)) — the length of the sequence, the number of elements initially placed in \(S\), and the number of games to simulate.
The second line contains \(n\) positive integers, where each integer is at most \(n\), representing the sequence.
outputFormat
Output exactly k lines. Each line should contain a single integer, the game result (i.e. Alice's score minus Bob's score) when both players play optimally.
sample
3 1 2
1 2 3
2
2
</p>