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>
using namespace std;
int main(){
int n, m;
cin >> n >> m;
int salaries[n];
int banknotes[m];
for(int i = 0; i < n; ++i) cin >> salaries[i];
for(int i = 0; i < m; ++i) cin >> banknotes[i];
int DP[1<<m][n+1];
memset(DP, -1, sizeof(DP));
DP[0][0] = 0;
for(int mask = 1; mask < (1 << m); ++mask){
for(int note = 0; note < m; ++note){
if(mask&(1<<note)){
DP[mask][0] = DP[mask^(1<<note)][0] + banknotes[note];
}
}
//cout << DP[mask][0] << endl;
}
bool IsPossible = false;
for(int person = 1; person <= n; ++person){
for(int mask = 1; mask < (1<<m); ++mask){
if(DP[mask][person-1] == salaries[person-1]) DP[mask][person] = 0;
for(int note = 0; note < m; ++note){
if(mask&(1<<note)){
if(DP[mask^(1 << note)][person] != -1){
DP[mask][person] = DP[mask^(1<<note)][person]+banknotes[note];
}
}
}
if((person == n) and (DP[mask][person] != -1)) IsPossible = true;
}
}
if(IsPossible) cout << "YES" << endl;
else cout << "NO" << endl;
return 0;
}
# | 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... |