PivotOJ

True or False Test

시간 제한: 3000ms메모리 제한: 2048MB출처: USACO 2025 February PlatinumBOJ 33740

문제

Bessie is taking an NN-question true or false test (1N21051\le N\le 2\cdot 10^5). For the ii-th question, she will gain aia_i points if she gets it correct, lose bib_i points if she gets it incorrect, or remain even if she does not answer it (0<ai,bi1090<a_i,b_i\le 10^9).

Bessie knows all the answers because she is a smart cow, but worries that Elsie (who is administering the test) will retroactively change up to kk of the questions after the test such that Bessie does not get those questions correct.

Given QQ (1QN+11\le Q\le N+1) candidate values of kk (0kN0\le k\le N), determine the number of points Bessie can guarantee for each kk, given that she must answer at least kk questions.

입력

The first line contains NN and QQ.

The next NN lines each contain aia_i and bib_i.

The next QQ lines each contain a value of kk. No value of kk appears more than once.

출력

The answer for each kk on a separate line.

예제

예제 1

입력
2 3
3 1
4 2
2
1
0
출력
-3
1
7
코드를 제출하려면 로그인하세요.