#BS0000124. Tuần lộc và xe trượt tuyết (Reindeer and Sleigh)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tuần lộc và xe trượt tuyết (Reindeer and Sleigh)
Reindeer and Sleigh
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
There are sleighs, numbered through . Sleigh requires reindeer, and each reindeer may pull at most one sleigh. Pulling multiple sleighs requires the sum of their respective requirements. For each of queries giving available reindeer, determine the maximum number of sleighs that can be pulled simultaneously. The answer may be zero.
Input
The first line contains . The second line contains requirements . Each of the next lines contains one number .
Output
Print lines, the maximum number of sleighs for each query.
Subtasks
- Subtask 1 (20 points): ; for , .
- Subtask 2 (30 points): ; for , .
- Subtask 3 (50 points): ; for , .
Examples
Input
4 3
5 3 11 8
16
7
1000
Output
3
1
4
Explanation
For , choose sleighs requiring reindeer; all four require , so the maximum is . For , the two smallest requirements sum to , so at most one sleigh can be pulled. For , all four can be pulled. The answers are 3, 1, and 4.