This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(int i=a;i<b;i++)
#define af(i,a,b) for(int i=a;i>=b;i--)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int maxN=2e5+5;
const ll inf=1e12;
int n,m;
vector<int> v,u;
bool xx=false;
int vis[30];
void prob(int i, int j){
/*f(l,0,n){
cout<<v[l]<<" ";
}
cout<<"\n";
f(l,0,m){
cout<<vis[l]<<" ";
}
cout<<"\n";
*/
if(i==n){
xx=true;
return;
}
if(v[i]==0){
f(x,0,m) prob(i+1,x);
return;
}
if(vis[j]==1) return;
if(v[i]<u[j]) return;
vis[j]=1;
v[i]-=u[j];
f(x,j+1,m){
prob(i,x);
}
v[i]+=u[j];
vis[j]=0;
}
void go(){
cin>>n>>m;
int a;
f(i,0,n){
cin>>a;
v.PB(a);
}
f(i,0,m){
cin>>a;
u.PB(a);
}
u.PB(0);
m++;
f(i,0,m) prob(0,i);
if(xx) cout<<"YES\n";
else cout<<"NO\n";
}
int main(){
fastio;
int test=1;
//cin>>test;
f(i,1,test+1){
//cout<<"Case "<<i<<":\n";
go();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |