#BS0000461. Quà năm mới (New Year's Problem)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Quà năm mới (New Year's Problem)
New Year's Problem
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Vlad must buy one gift for each of his friends. Buying friend a gift at shop yields joy . He may visit at most of the shops and purchase multiple gifts per visited shop. Maximize the minimum joy among all friends.
Input
The first line contains . Each of the next lines contains integers .
Output
Print the maximum achievable minimum joy.
Subtasks
- Subtask 1 (20 points): ; ; ; (, ).
- Subtask 2 (30 points): ; ; ; (, ).
- Subtask 3 (50 points): ; ; ; (, ).
Examples
Example 1
Input
2 2
1 2
3 4
Output
3
Explanation
Visit shop 2: joys 3 and 4. Friend 1 cannot exceed 3.
Example 2
Input
4 3
1 3 1
3 1 1
1 2 2
1 1 3
Output
2
Explanation
Use shops 2 and 3 for joys 3,2,2. Threshold 3 requires three separate shops.
Example 3
Input
2 3
5 3 4
2 5 1
Output
4
Explanation
Use both shops for joys 5,5,4; friend 3 is capped at 4.
Example 4
Input
4 2
7 9
8 1
9 6
10 8
Output
8
Explanation
Use shop 4 for 10 and 8. No row has both entries above 8.
Example 5
Input
2 4
6 5 2 1
7 9 7 2
Output
2
Explanation
Visit shop 2; friend 4 cannot exceed 2.