In this problem, you are initially given an empty multiset. You have to process two types of queries:
- ADD x x x — add an element equal to 2 x 2^{x} 2x to the multiset;
- GET w w w — say whether it is possible to take the sum of some subset of the current multiset and get a value equal to w w w.
Input
The first line contains one integer m m m ( 1 ≤ m ≤ 1 0 5 1 \le m \le 10^5 1≤m≤105) — the number of queries.
Then
m
m
m lines follow, each of which contains two integers
t
i
t_i
ti,
v
i
v_i
vi, denoting the
i
i
i-th query. If
t
i
=
1
t_i = 1
ti=1, then the
i
i
i-th query is ADD
v
i
v_i
vi (
0
≤
v
i
≤
29
0 \le v_i \le 29
0≤vi≤29). If
t
i
=
2
t_i = 2
ti=2, then the
i
i
i-th query is GET
v
i
v_i
vi (
0
≤
v
i
≤
1
0
9
0 \le v_i \le 10^9
0≤vi≤109).
Output
For each GET query, print YES if it is possible to choose a subset with sum equal to w w w, or NO if it is impossible.
#include<bits/stdc++.h>
using namespace std;
int f[32],cnt[32];
void slove()
{
int t;
cin >> t;
if (t == 1)
{
int v;
cin >> v;
cnt[v]++;
}
else
{
int w;
cin >> w;
for (int i = 29; i >= 0; i--)
w -= f[i] * min(w / f[i], cnt[i]);
cout << (w ? "NO" : "YES") << endl;
}
}
int main()
{
int m;
cin >> m;
f[0] = 1;
for (int i = 1; i <= 29; i++)f[i] = f[i - 1] * 2;
while (m--)
{
slove();
}
}