#SGM0000077. Truy vấn tổng xu bị thiếu (Missing Coin Sum Queries)
Truy vấn tổng xu bị thiếu (Missing Coin Sum Queries)
Missing Coin Sum Queries
Source: CSES
Version: Phuoc Hung OJ Extended
Problem
Coin has positive value . Query allows each coin in that index range to be used at most once. Find the smallest positive sum that cannot be formed by a subset of those coins.
Input
The first line contains , the second line the coin values, and the next lines contain .
Output
Print the smallest missing positive subset sum for every query.
Subtasks
Subtask 1 (20%)
- , number of queries .
- All other conditions are the same as Subtask 3.
Subtask 2 (30%)
- , number of queries .
- All other conditions are the same as Subtask 3.
Subtask 3 (50%)
Example
Input
5 3
2 9 1 2 7
2 4
4 4
1 5
Output
4
1
6
Explanation
For range [2,4], coins are [9,1,2]. Sums are possible, but is not.