PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000137. Truy vấn ăn kẹo (Eating Queries)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Truy vấn ăn kẹo (Eating Queries)
Eating Queries
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Timur has candies; candy contains units of sugar. For each independent target , determine the minimum number of distinct candies whose total sugar is at least , or output -1 if even all candies are insufficient. Candies can be reused in different queries.
Input
The first line contains . The second line contains values . Each of the next lines contains target .
Output
Print lines in query order: the minimum number of candies, or -1 if impossible.
Subtasks
- Subtask 1 (20 points): ; ; for every ; for every .
- Subtask 2 (30 points): ; ; for every ; for every .
- Subtask 3 (50 points): ; ; for every ; for every .
Examples
Input
8 7
4 3 3 1 1 4 5 9
1
10
50
14
15
22
30
Output
1
2
-1
2
3
4
8
Explanation
Sorting descending gives ; prefix sums for through candies are . Targets require respectively candies. In particular, two candies can give at most , so the target requires three.