#QHD0000080. Cuộc thi tài năng (Talent Show)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Cuộc thi tài năng (Talent Show)
Talent Show
Source: USACO
Version: Phuoc Hung OJ Extended
Problem Statement
There are cows numbered through . Cow has positive integer weight and positive integer talent . Choose a nonempty group of cows whose total weight is at least . The objective is to maximize the ratio of total talent to total weight.
For a subset , 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 , so a feasible subset always exists. Let be the best ratio. Print exactly . No cow indices are required.
The total chosen weight may exceed : is a minimum requirement, not a capacity limit.
Input
The first line contains . Each of the next lines contains .
Output
Print the integer .
Subtasks
-
Subtask 1 (20 points): ; ; ; .
-
Subtask 2 (30 points): ; ; ; ; .
-
Subtask 3 (50 points): ; ; ; ; .
Examples
Example 1
Input
3 15
20 21
10 11
30 31
Output
1066
Explanation
Choose cows 1 and 2, yielding talent , weight , and .
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 and result .