#P11847. [USACO25FEB] True or False Test P

    ID: 11489 远端评测题 3000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DPUSACO2025决策单调性

[USACO25FEB] True or False Test P

Description

Note: The time limit for this problem is 3s, 1.5x the default. The memory limit for this problem is 512MB, twice the default.

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.

Input Format

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.

Output Format

The answer for each kk on a separate line.

2 3
3 1
4 2
2
1
0
-3
1
7

Hint

For each value of kk, it is optimal for Bessie to answer all of the questions.

SCORING:

  • Inputs 2-4: N100N\le 100
  • Inputs 5-7: Q10Q\le 10, N2105N\le 2\cdot 10^5
  • Inputs 7-20: No additional constraints.