#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){
prob(i+1,0);
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);
}
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
4 ms |
212 KB |
Output is correct |
9 |
Correct |
6 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
4 ms |
212 KB |
Output is correct |
9 |
Correct |
6 ms |
212 KB |
Output is correct |
10 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |