PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#CT0000150. Túi sách kiến thức (Knowledge Book Bag)

Bài tập này chưa được xếp vào lộ trình.

Túi sách kiến thức (Knowledge Book Bag)

Knowledge Book Bag

Version: Phuoc Hung OJ Extended

Problem Statement

For an extracurricular trip, Minh can choose from nn available books. Book ii has a positive integer weight wiw_i and provides viv_i knowledge points. Minh's bag can carry a total weight of at most WW.

Each book may be selected at most once. Choosing no books is allowed.

The primary goal is to maximize the total knowledge points. Among selections with the same maximum total, Minh prefers the one with the fewest books. The chosen book indices need not be printed.

Find the maximum total knowledge points and the minimum number of books among selections attaining that maximum.

Input

The first line contains two positive integers nn and WW.

Each of the next nn lines contains positive integers wiw_i and viv_i, the weight and knowledge value of book ii.

Output

Print two integers on one line: the maximum total knowledge points and the minimum number of books among selections achieving that value. If no book fits, print 0 0.

Subtasks

  • Subtask 1 (30 points): 1≤n≤201\le n\le 20; 1≤W≤1001\le W\le 100; 1≤wi≤1051\le w_i\le 10^5 and 1≤vi≤1061\le v_i\le 10^6 for every 1≤i≤n1\le i\le n.
  • Subtask 2 (30 points): 1≤n≤801\le n\le 80; 1≤W≤20001\le W\le 2000; 1≤wi≤1051\le w_i\le 10^5 and 1≤vi≤1061\le v_i\le 10^6 for every 1≤i≤n1\le i\le n.
  • Subtask 3 (40 points): 1≤n≤2001\le n\le 200; 1≤W≤2⋅1041\le W\le 2\cdot 10^4; 1≤wi≤1051\le w_i\le 10^5 and 1≤vi≤1061\le v_i\le 10^6 for every 1≤i≤n1\le i\le n.

Examples

Example 1

Input

4 7
3 6
4 8
7 14
2 3

Output

14 1

Explanation

Book 33 has weight 77 and value 1414, so it fits. Books 11 and 22 also fit together (3+4=73+4=7) and yield 6+8=146+8=14, but use two books. No feasible selection exceeds 1414 points. The tie-break selects one book, yielding 14 1.

Example 2

Input

3 5
2 4
3 5
4 7

Output

9 2

Explanation

Selecting books 11 and 22 uses weight 2+3=52+3=5 and provides 4+5=94+5=9. Book 33 provides 77, but cannot be combined with either other book without exceeding weight 55. Therefore the optimum is 99 points using 22 books.

Example 3

Input

3 2
3 5
4 100
5 1

Output

0 0

Explanation

The capacity is W=2W=2, but the three books weigh 3,4,53,4,5, each exceeding the capacity. Minh chooses no books; both total value and count are 00.