第六回日本最強プログラマー学生選手権-予選-(AtCoder Regular Contest 201)
B
Binary Knapsack
AtCoder
⌀ 1808
原题
← AC →
翻译中…

Problem Statement

翻译中…

There are $N$ items numbered $1,2,\dots,N$. Item $i$ has weight $2^{X_i}$ and value $Y_i$.

翻译中…

When choosing $0$ or more items such that the sum of weights is at most $W$, find the maximum possible sum of values.

翻译中…

$T$ test cases are given, so find the answer for each.

翻译中…

Constraints

翻译中…
  • $1 \le T \le 10^5$
  • $1 \le N \le 2 \times 10^5$
  • $1 \le W \le 10^{18}$
  • $0 \le X_i \lt 60$
  • $1 \le Y_i \le 10^9$
  • The sum of $N$ over all test cases is at most $2 \times 10^5$.
  • All input values are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T

翻译中…

Each test case is given in the following format:

翻译中…

N W
X_1 Y_1
X_2 Y_2
\vdots
X_N Y_N

翻译中…

Output

翻译中…

Output $T$ lines.

翻译中…

The $i$-th line should contain the maximum possible sum of values for the $i$-th test case.

翻译中…

样例

Input #1
3
4 16
0 3
3 2
4 5
3 4
1 576460752303423487
59 1000000000
15 23752394551518
42 457687868
42 527769950
41 336200204
42 555090674
32 452384
42 697175056
38 62269946
39 24293218
40 214670437
37 6306990
39 103832403
41 205334902
37 20326312
35 4723060
42 176783630
Output #1
7
0
3102936938
For the first test case, the pairs of weight and value for items $1,2,3,4$ are $(1,3),(8,2),(16,5),(8,4)$, respectively. If we choose items $1$ and $4$, the sum of weights is $1+8=9 (\le 16)$ and the sum of values is $3+4=7$. For the second test case, note that it is allowed to choose $0$ items.
题目信息

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。