Knapsack

아직 제출이 없습니다시간 제한3초메모리 제한512 MB

문제

To fit the best stuff in a sack with limits on what you can pack recursion will do if memoized too but DP puts less on the stack.

You are given a classic knapsack problem: a set of elements (w_1,v_1),,(w_n,v_n)(w\_1, v\_1), \dots, (w\_n, v\_n) and a capacity WW. Solve

max_S\[n]_iSw_iW_iSv_i.\max\_{\substack{S \subseteq \[n]\\\\\sum\_{i\in S} w\_i \leq W}} \sum\_{i \in S} v\_i\text{.}

Here, \[n]\[n] is the list of integers from 11 through nn.

You are guaranteed that 0n5000 \leq n \leq 500, 0w_iW10170 \leq w\_i \leq W \leq 10^{17}, and 0v_i10160 \leq v\_i \leq 10^{16}. Furthermore, you are guaranteed that the w_iw\_i have been "smoothed" as described in the next paragraph.

A problem instance complying with the above bounds is constructed. Then a randomizing filter is applied to the problem instance as follows: Let BB be the weight of the element of maximum weight. Now the following update is applied to each weight:

w_imin(w_i+\mboxrand(.05B),W)w\_i \leftarrow \min (w\_i + \mbox{rand}(\lfloor .05 B \rfloor), W)

Here \mboxrand(A)\mbox{rand}(A) is a function that generates a uniform random integer in \[0,A1]\[0, A-1]. This process is applied only to the w_iw\_i, not to WW or any of the other values.

입력

The first line contains the two space-separated integers nn and WW. Each of the next nn lines contains two space-separated integers w_iw\_i and v_iv\_i.  The element weights were generated as described above.  First the items are chosen in compliance with all the bounds.  Then the smoothing algorithm is applied.  The result is what your program will receive as input.

출력

Output one line with the value of the given knapsack problem instance.