#P6294. [eJOI 2017] 游戏
[eJOI 2017] 游戏
Description
Alice and Bob are once again playing a game.
They have a sequence of positive integers, each . The elements in the sequence are indexed from to . The sequence may contain duplicate numbers. At the start of the game, there is a multiset containing the first elements of the sequence. The two players now begin the game, with Alice moving first. In each step:
- The player chooses a number from and removes it from , then adds the value of this removed number to their score (initially, both scores are zero).
- The next number in the sequence (if any remain) is added to the multiset (if the sequence is already empty, skip this operation). That is, after the first removal from , the -th number of the sequence is added to ; after the second removal, the -th number is added, and so on.
The game continues until becomes empty. We assume both players are very smart (i.e., they always act to maximize their own benefit). The result of the game is defined as Alice's score minus Bob's score.
Now, your task is to write a program to compute the results of games (all using the same given sequence).
Input Format
The first line contains two positive integers .
The second line contains positive integers , describing the initial sequence of the game.
The third line contains positive integers , where means that in the -th game, .
Output Format
Output positive integers, one per line.
The -th positive integer indicates the result of the -th game.
5 2
2 4 2 3 5
4 3
2
6
Hint
Explanation of Sample 1
The input specifies that you need to process games. The sequence is the same in both games, and only the initial multiset is different. In the first game it is , and in the second it is .
Constraints
- For the first of the testdata, .
- For the first of the testdata, .
- For the first of the testdata, .
- For all testdata, $1\le n\le 10^5,1\le k\le 2\times 10^3,k\le n,a_i\in[1,n],p_i\in[1,n]$.
Notes
The original problem is from: eJOI2017 Problem F. Game.
Translated by ChatGPT 5
京公网安备 11011102002149号