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 <iostream>
#include <vector>
using namespace std;
#define fastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
fastIO;
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> peopleCovered((1<<m), -1);
vector<int> moneyLeft((1<<m), -1);
peopleCovered[0] = 0;
moneyLeft[0] = 0;
for(int mask = 0; mask<(1<<m); mask++){
for(int i=0; i<m; i++){
if(mask&(1<<i)){
int prevMask = mask & ~(1<<i);
if(peopleCovered[prevMask]==-1) continue;
int newMoney = moneyLeft[prevMask] + b[i];
int curTarget = a[peopleCovered[prevMask]];
if(newMoney < curTarget){
peopleCovered[mask] = peopleCovered[prevMask];
moneyLeft[mask] = newMoney;
}
else if(newMoney == curTarget){
peopleCovered[mask] = peopleCovered[prevMask] + 1;
moneyLeft[mask] = 0;
}
}
}
if(peopleCovered[mask]==n){
cout << "YES" << '\n';
return 0;
}
}
cout << "NO" << '\n';
}
# | 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... |