This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#ifndef Local
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#endif
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define lim 100000
using namespace std;
const int mod=1000000007ll;
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];
}
pair<int,int>dp[1<<m];
dp[0]={0,0};
for(int i=1;i<(1<<m);i++){
dp[i]={-1,INT_MAX};
for(int j=0;j<m;j++){
if(i&(1<<j)){
dp[i]=max(dp[i],{dp[i-(1<<j)].first,dp[i-(1<<j)].second+b[j]});
//cerr<<"set "<<i<<" "<<j<<" "<<(i-(1<<j))<<"\n";
}
}
if(i!=n&&dp[i].second==a[dp[i].first]){
dp[i].first++;
dp[i].second=0;
}
}
/*
for(int i=0;i<(1<<m);i++){
cerr<<dp[i].first<<" "<<dp[i].second<<"\n";
}
*/
if(dp[(1<<m)-1].first==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.txt","r",stdin);
freopen("out.txt","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... |