#BS0000402. Chọn cặp số (Pair Selection)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Chọn cặp số (Pair Selection)
Pair Selection
Version: Phuoc Hung OJ Extended
PHOJ practice edition. Its constraints, input/output format, examples and judging rules are specified below.
Statement
Given pairs of positive integers , choose exactly distinct indices forming a set to maximize $$\frac{\sum_{i\in S}a_i}{\sum_{i\in S}b_i}.$$ Print the maximum ratio.
Input
The first line contains integers . Each of the next lines contains integers .
Output
Print the maximum ratio. Absolute error must not exceed . The output token may contain at most 128 characters; in scientific notation, the explicit exponent must be from -1000 to 1000.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; ; .
New examples
Input
3 2
10 2
6 1
8 4
Output
5.333333333333333
Explanation
There are three ways to choose two pairs. Pairs 1 and 2 yield . Pairs 1 and 3 yield , while pairs 2 and 3 yield . The maximum is , approximately .
Input
3 1
2 5
9 2
4 1
Output
4.5
Explanation
Only one pair is selected, so the possible ratios are , , and . The maximum is 4.5, attained by the second pair.
Input
2 2
1 3
5 2
Output
1.2
Explanation
Since , both pairs must be selected. The numerator is and the denominator is , yielding .