이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#ifndef Local
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#endif
#include <bits/stdc++.h>
#define pb push_back
#define lim 100000
using namespace std;
void solve(){
int n,m;
cin>>n>>m;
int a[n],b[m];
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<m;i++){
cin>>b[i];
}
int dp[1<<m],left[1<<m];
int lll[1<<m];
for(int i=0;i<m;i++){
lll[1<<i]=i;
}
dp[0]=left[0]=0;
for(int i=1;i<(1<<m);i++){
dp[i]=-1;
left[i]=INT_MAX;
int j=i;
while(j){
int k=j&-j;
j^=k;
if(dp[i]<dp[i^k]){
dp[i]=dp[i^k];
left[i]=left[i^k]+b[lll[k]];
if(left[i]<=a[dp[i]])break;
}
}
if(i!=n&&left[i]==a[dp[i]]){
dp[i]++;
left[i]=0;
}
}
/*
for(int i=0;i<(1<<m);i++){
cerr<<dp[i].first<<" "<<dp[i].second<<"\n";
}
*/
if(dp[(1<<m)-1]==n){
cout<<"YES\n";
}else{
cout<<"NO\n";
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
#ifdef Local
freopen(".in","r",stdin);
freopen(".out","w",stdout);
#endif
int t=1;
//cin>>t;
while (t--)
{
solve();
}
}
# | 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... |