#include <bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define int long long
#define pb push_back
#define all(x) (x.begin(),x.end())
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const ll N = 2e6+7, INF = 1e18 , inf = 1e6, mod = 1e9+7;
int a[22];
int b[22];
int have[N];
vector<int> good(N,-1);
signed main(){
// #pragma GCC optomize ("Ofast")
// #pragma GCC optomize ("unroll-loops")
// #pragma GCC target ("avx,avx2,fma")
ios;
int tt=1;
// cin>>tt;
while(tt--){
int n,m;
cin>>n>>m;
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<m;i++)cin>>b[i];
good[0]=0;
for(int mask=0;mask<(1<<m);mask++){
for(int i=0;i<m;i++){
if((mask & (1<<i))==0){
int nwmask=mask + (1<<i);
if(a[good[mask]]==-1)continue;
int use=have[mask]+b[i];
int chel=a[good[mask]];
if(use<chel){
good[nwmask]=good[mask];
have[nwmask]=use;
}else if(use==chel){
good[nwmask]=good[mask]+1;
have[nwmask]=0;
}
}
}
}
for(int mask=0;mask<(1<<m);mask++){
if(good[mask]==n){
cout<<"YES";
return 0;
}
}
cout<<"NO";
}
}
# | 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... |