This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast,unroll-loops,inline")
#pragma GCC target("avx,avx2,bmi,popcnt")
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define prec fixed<<setprecision
#define endl '\n'
#define all(x) x.begin(),x.end()
#define pll pair<ll,ll>
#define open(name) if(fopen(name".inp", "r")){freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout);}
#define fout(name) freopen(name".out", "w", stdout);
using namespace std;
const int maxN=1e5+69;
const int maxM=1<<20;
const int mod=1e9+7;
const int bs=448;
int n,m,a[maxN],b[maxN];
ll w[maxM],c[maxM];
void Enter(){
cin>>n>>m;
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<m;i++)cin>>b[i];
memset(c,-1,sizeof c);
c[0]=0;
for(int mask=0;mask<(1<<m);mask++){
for(int i=0;i<m;i++){
ll sub=mask^(1<<i);
if(((mask>>i)&1)&&c[sub]!=-1){
ll weight=w[sub]+b[i];
if(weight<a[c[sub]]){
c[mask]=c[sub];
w[mask]=weight;
} else if(weight==a[c[sub]])c[mask]=c[sub]+1;
}
}
if(c[mask]==n){
cout<<"YES";
return;
}
}
cout<<"NO";
}
//amogus
signed main(){
//open("seq198");
cin.tie(nullptr);ios_base::sync_with_stdio(NULL);
ll t=1;
//cin>>t;
while(t--)
Enter();
}
# | 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... |