PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000129. Món hàng đẹp nhất theo ngân sách (Most Beautiful Item for Each Query)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Món hàng đẹp nhất theo ngân sách (Most Beautiful Item for Each Query)
Most Beautiful Item for Each Query
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
There are items. Item has price and beauty . For each of the independent budgets , choose at most one item whose price does not exceed , maximizing its beauty. If no item is affordable, answer .
Input
The first line contains . Each of the next lines contains . The final line contains budgets .
Output
Print integers in query order, separated by spaces.
Subtasks
- Subtask 1 (20 points): ; ; , , .
- Subtask 2 (30 points): ; ; , , .
- Subtask 3 (50 points): ; ; , , .
Examples
Input
5 6
1 2
3 2
2 4
5 6
3 5
1 2 3 4 5 6
Output
2 4 5 5 6 6
Explanation
Budget allows only beauty . Budget adds the item of beauty . Budget allows four items and the best beauty is ; budget adds none. Budgets and can afford beauty . Therefore print 2 4 5 5 6 6.