True or False Test

시간 제한3초메모리 제한2048 MB

요약
엘시가 최대 k개 문항을 뒤집을 수 있을 때, 베시가 k개 이상 답하여 보장받는 최대 점수를 각 k마다 구한다.
난이도

어려움10점 중 8점

유형
정렬, 누적 합, 그리디, 이분 탐색
정답자
아직 제출이 없습니다

문제

Bessie is taking an NN-question true or false test (1≤N≤2⋅1051\le N\le 2\cdot 10^5). For the ii-th question, she will gain a_ia\_i points if she gets it correct, lose b_ib\_i points if she gets it incorrect, or remain even if she does not answer it (0\<a_i,b_i≤1090\<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 (1≤Q≤N+11\le Q\le N+1) candidate values of kk (0≤k≤N0\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 a_ia\_i and b_ib\_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

  1. 예제 1

    입력
    2 3
    3 1
    4 2
    2
    1
    0
    
    예상 출력
    -3
    1
    7