WA后五个点求条
查看原帖
WA后五个点求条
1059234
Ybw0731楼主2025/1/27 12:00
#include<bits/stdc++.h>
#define ll long long
#define PII pair<int,int>
using namespace std;
const int N=5e5+5;
const ll INF=0x3f3f3f3f3f3f;
const double EPS=1e-6;
ll n,m,dp[N];
void solve(){
	cin>>n>>m;
	dp[0]=1;
	for(int i=1;i<=n;i++){
		ll k,a;
		cin>>k>>a;
		for(int j=1;j<=a;j*=2){
			for(int l=N;l>=k*j;l--)dp[l]|=dp[l-k*j];
			a-=j;
		}
	}
	while(m--){
		int t;
		cin>>t;
		if(dp[t]==1)cout<<"Yes\n";
		else cout<<"No\n";
	}
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	int T=1;
//	cin>>T;
	while(T--)solve();
	return 0;
}
2025/1/27 12:00
加载中...