This page is still under construction.

Parts of this page are still being built. What you see may change.

Game

Time limit2sMemory limit512 MB

Summary
For each starting size P, two players alternately take a number from a buffer that refills with later sequence elements, and we report Alice's score minus Bob's.
Level

Medium7 of 10

Topics
Greedy, Sorting, Game theory, Prefix sum
Solved
No attempts yet

Problem

Alice and Bob play the following game.

There is a sequence of NN positive integers numbered from 11 to NN. Each element is at most NN, and equal values may appear more than once. At the start of a game, the first PP elements of the sequence form a multiset SS. Alice moves first, and the two players alternate turns. Each turn proceeds as follows:

  1. The player to move chooses one number from SS, removes it, and adds its value to their own score. Both scores start at 00.
  2. If the sequence still has an element that has not entered SS, the earliest such element is added to SS. That is, after the first removal the element with index P+1P+1 is added, after the second removal the element with index P+2P+2 is added, and so on. If the sequence is already exhausted, nothing is added.

Play continues until SS becomes empty. Each player tries to maximize their own final score. The result of a game is Alice's score minus Bob's score.

Write a program game that processes KK games played on one given starting sequence, where the games differ only in their starting sizes.

Input

The first line of the standard input contains two positive integers NN and KK, separated by a space.

The second line contains NN positive integers a1,a2,…,aNa_1, a_2, \dots, a_N, separated by spaces, representing the elements of the given sequence.

The third line contains KK positive integers p1,p2,…,pKp_1, p_2, \dots, p_K, separated by spaces. The ii-th game starts from the set SS built from the first pip_i elements of the sequence, where i=1,2,…,Ki = 1, 2, \dots, K.

Output

Print KK lines to the standard output. The ii-th line contains a single integer, the result of the ii-th game. The games are numbered from 11 to KK in the order given by the input.

Constraints

  • 1≤N≤1000001 \le N \le 100000
  • 1≤K≤20001 \le K \le 2000
  • K≤NK \le N
  • 1≤ai≤N1 \le a_i \le N for every i=1,2,…,Ni = 1, 2, \dots, N
  • 1≤pi≤N1 \le p_i \le N for every i=1,2,…,Ki = 1, 2, \dots, K
  • In 10%10\% of the tests: 1≤N≤101 \le N \le 10
  • In 30%30\% of the tests: 1≤N≤6001 \le N \le 600
  • In 50%50\% of the tests: 1≤N≤100001 \le N \le 10000, 1≤K≤10001 \le K \le 1000

Hint

Each game lasts exactly NN moves. Alice takes the numbers on the odd-numbered turns, and Bob takes the numbers on the even-numbered turns. While arrivals remain, one new number enters SS after every turn, so SS always holds PP numbers at the start of a turn during that phase. Once arrivals run out, the rest of SS is removed in order until it is empty.

Examples2

  1. Example 1

    Input
    5 2
    2 4 2 3 5
    4 3
    
    Expected output
    2
    6
    
  2. Example 2

    Input
    1 1
    1
    1
    
    Expected output
    1