显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
const int N = 210 * 20,M = 500010;
int n,m,t;
int a[N],s[M],b[M];
int main(){
freopen("noi_online2020_watch.in","r",stdin);
freopen("noi_online2020_watch.out","w",stdout);
scanf("%d%d",&n,&m);
for(int i = 1;i <= n;i++){
int x,y;
scanf("%d%d",&x,&y);
int p = 1;
while(y >= p){
y -= p;t++;
a[t] = x * p;
p <<= 1;
}
if(y > 0){
t++;a[t] = y * x;
}
}
int ma = 0;
for(int i = 1;i <= m;i++){
scanf("%d",&b[i]);
ma = max(ma,b[i]);
}
s[0] = 1;
for(int i = 1;i <= t;i++){
for(int j = ma;j >= a[i];j--){
s[j] = max(s[j],s[j-a[i]]);
}
}
for(int i = 1;i <= m;i++){
if(s[b[i]])printf("Yes\n");
else printf("No\n");
}
return 0;
}