Alibaba and Debt
Time: 1 s
Memory: 125 MB
Memory: 125 MB
Alibaba came out of a magical cave with N treasures. The value of the \(\boldsymbol{i^{th}}\) treasure is \(\boldsymbol{2^{a_i}}\) taka. All \(\boldsymbol{a_i}\) are distinct.
Unfortunately, Alibaba is in debt — but he has forgotten the exact amount. He has Q repayment options, each suggesting a possible debt amount and a constraint on the number of treasures he can use.
Each option consists of two integers, D and M. It assumes Alibaba's debt is \(\boldsymbol{2^D}\) Taka, and he can use at most M treasures to repay it. He can use each treasure at most once, and the total value of the selected treasures must be at least \(\boldsymbol{2^D}\) Taka to repay the debt.
Alibaba wants to know whether it is possible to fully pay off the debt. Can you determine whether it's possible?
Each option is independent and must be answered separately.
Unfortunately, Alibaba is in debt — but he has forgotten the exact amount. He has Q repayment options, each suggesting a possible debt amount and a constraint on the number of treasures he can use.
Each option consists of two integers, D and M. It assumes Alibaba's debt is \(\boldsymbol{2^D}\) Taka, and he can use at most M treasures to repay it. He can use each treasure at most once, and the total value of the selected treasures must be at least \(\boldsymbol{2^D}\) Taka to repay the debt.
Alibaba wants to know whether it is possible to fully pay off the debt. Can you determine whether it's possible?
Each option is independent and must be answered separately.
Input
The first line contains two integers N and Q — the number of treasures and the number of repayment options.The second line contains N distinct integers \(\boldsymbol{(a_1, a_2, ..., a_N)}\) — each representing the exponent of a treasure's value (i.e., the \(\boldsymbol{i^\text{th}}\) Treasure is worth \(\boldsymbol{2^{a_i}}\) taka).
The next Q lines each contain two integers D and M. Where D is the exponent of the debt amount (i.e., the debt is \(\boldsymbol{2^D}\)) and M is the maximum number of treasures Alibaba can use.
Constraint
\(1 \leq \boldsymbol{N, Q} \leq 10^5 \) \(0 \leq \boldsymbol{M} \leq N\)
\(1 \leq \boldsymbol{D, a_i} \leq 10^9\)
Output
For each query, print "YES" (without quotes) if Alibaba can repay the debt.Otherwise, print "NO".
Examples
| Input | Output |
|---|---|
|
3 2
1 2 4 10 2 2 1 |
NO
YES |
| Input | Output |
|---|---|
|
5 1
10 1 13 2 9 13 5 |
YES
|
Problem Info
| Problem ID | 478 |
| Time Limit | 1000 ms |
| Memory Limit | 128000 KB |
| Moderators | muhimin , mahdi_talukder , Royboy01 |
Statistics
Submit
You need to Login or Registration for submit your solution