This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
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];
}
vector<int> s(1<<m,-1),c(1<<m,-1);
s[0]=0;
c[0]=0;
int z=0;
for(int i=1;i<1<<m;i++){
for(int j=0;j<m;j++){
if(i&(1<<j)){
if(s[i^(1<<j)]!=-1){
int k=c[i^(1<<j)]+b[j];
if(k<a[s[i^(1<<j)]]){
c[i]=k;
s[i]=s[i^(1<<j)];
}
else if(k==a[s[i^(1<<j)]]){
s[i]=s[i^(1<<j)]+1;
c[i]=0;
}
}
}
if(s[i]==n){
z=1;
break;
}
}
}
if(z){
cout<<"YES";
}
else{
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... |