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

#QHD0000080. Cuộc thi tài năng (Talent Show)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

2 lộ trình

Cuộc thi tài năng (Talent Show)

Talent Show

Source: USACO

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn cows numbered 11 through nn. Cow ii has positive integer weight wiw_i and positive integer talent tit_i. Choose a nonempty group of cows whose total weight is at least WW. The objective is to maximize the ratio of total talent to total weight.

For a subset SS, the ratio is

$$R(S)=\frac{\sum_{i\in S}t_i}{\sum_{i\in S}w_i},\qquad \sum_{i\in S}w_i\ge W.$$

It is guaranteed that the combined weight of all cows is at least WW, so a feasible subset always exists. Let R∗R^* be the best ratio. Print exactly ⌊1000R∗⌋\lfloor1000R^*\rfloor. No cow indices are required.

The total chosen weight may exceed WW: WW is a minimum requirement, not a capacity limit.

Input

The first line contains n,Wn,W. Each of the next nn lines contains wi,tiw_i,t_i.

Output

Print the integer ⌊1000R∗⌋\lfloor1000R^*\rfloor.

Subtasks

  • Subtask 1 (20 points): 1≤n≤101\le n\le10; 1≤W≤401\le W\le40; 1≤wi,ti≤1001\le w_i,t_i\le100; ∑wi≥W\sum w_i\ge W.

  • Subtask 2 (30 points): 1≤n≤701\le n\le70; 1≤W≤2001\le W\le200; 1≤wi≤30001\le w_i\le3000; 1≤ti≤10001\le t_i\le1000; ∑wi≥W\sum w_i\ge W.

  • Subtask 3 (50 points): 1≤n≤2501\le n\le250; 1≤W≤10001\le W\le1000; 1≤wi≤1061\le w_i\le10^6; 1≤ti≤10001\le t_i\le1000; ∑wi≥W\sum w_i\ge W.

Examples

Example 1

Input

3 15
20 21
10 11
30 31

Output

1066

Explanation

Choose cows 1 and 2, yielding talent 3232, weight 3030, and ⌊1000⋅32/30⌋=1066\lfloor1000\cdot32/30\rfloor=1066.

Example 2

Input

2 10
10 1
1 100

Output

9181

Explanation

The weight-10 cow is required; adding the weight-1 cow gives ratio 101/11101/11 and result 91819181.