#P6294. [eJOI 2017] 游戏

[eJOI 2017] 游戏

Description

Alice and Bob are once again playing a game.

They have a sequence of nn positive integers, each n\le n. The elements in the sequence are indexed from 11 to nn. The sequence may contain duplicate numbers. At the start of the game, there is a multiset SS containing the first pp elements of the sequence. The two players now begin the game, with Alice moving first. In each step:

  1. The player chooses a number from SS and removes it from SS, then adds the value of this removed number to their score (initially, both scores are zero).
  2. The next number in the sequence (if any remain) is added to the multiset SS (if the sequence is already empty, skip this operation). That is, after the first removal from SS, the (p+1)(p+1)-th number of the sequence is added to SS; after the second removal, the (p+2)(p+2)-th number is added, and so on.

The game continues until SS 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 kk games (all using the same given sequence).

Input Format

The first line contains two positive integers n,kn,k.

The second line contains nn positive integers a1,a2,...,ana_1,a_2,...,a_n, describing the initial sequence of the game.

The third line contains kk positive integers p1,p2,...,pkp_1,p_2,...,p_k, where pip_i means that in the ii-th game, p=pip=p_i.

Output Format

Output kk positive integers, one per line.

The ii-th positive integer indicates the result of the ii-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 22 games. The sequence is the same in both games, and only the initial multiset SS is different. In the first game it is {2,4,2,3}\{2, 4, 2, 3\}, and in the second it is {2,4,2}\{2,4,2\}.

Constraints

  • For the first 10%10\% of the testdata, 1n101\le n\le 10.
  • For the first 30%30\% of the testdata, 1n6001\le n\le 600.
  • For the first 50%50\% of the testdata, 1n104,1k1031\le n\le 10^4,1\le k\le 10^3.
  • 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