#include <bits/stdc++.h>
using namespace std;
#define lo long
int b[100003],n,m,s[100003],sum[100003];
int g[100003],d[23][100003],jam[100003];
string ans="NO";
int main(){std::ios::sync_with_stdio(false);
cin>>n>>m;
for(int i=0;i<n;i++)
{
cin>>b[i];
sum[i]=sum[i-1]+b[i];
}
for(int i=0;i<m;i++)
{
cin>>g[i];
}
for(int i=0;i<(1<<m);i++)
{
for(int j=0;j<m;j++)
{
if(!((i>>j)&1))
{
jam[i|(1<<j)]=jam[i]+g[j];
}
}
}
d[0][0]=1;
for(int i=0;i<=n;i++)
{
for(int j=0;j<(1<<m);j++)
{
if(!d[i][j])
{
continue;
}
if(i==n)
{
ans="YES";
break;
}
if(sum[i]==b[i])
{
d[i+1][j]=1;
}
for(int t=0; t<m; t++)
{
if(!((j>>t)&1))
{
d[i][j|(1<<t)]=1;
}
}
}
}
cout<<ans<<endl;
}
/*
* *
* * * *
* * * *
* * * *
* * * *
* * *
* *
* *
* *
* *
* *
* *
* *
* *
*
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
576 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
656 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |