显示代码纯文本
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <bitset>
using namespace std;
bitset <500001> dp;
int n ,m;
int main () {
freopen ("noi_online2020_watch.in","r",stdin);
freopen ("noi_online2020_watch.out","w",stdout);
scanf ("%d%d",&n ,&m);
int sum ,val ,x;
dp[0] = 1;
for (int q = 1;q <= n;++ q) {
scanf ("%d%d",&val ,&sum);
for (int w = 1;sum >= w;w <<= 1) {
dp |= dp << w * val;
sum -= w;
}
if (sum * val) {
dp |= dp << sum * val;
}
}
while (m --) {
scanf ("%d",&x);
puts (dp[x] ? "Yes" : "No");
}
return 0;
}