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;
typedef long long ll;
typedef long double ld;
#define ff first
#define ss second
int main(){
ios_base::sync_with_stdio(false), cin.tie(NULL);
// freopen("bank.in", "r", stdin);
// freopen("bank.out", "w", stdout);
int p, m;
cin >> p >> m;
vector<int> people(p);
vector<int> money(m);
for(int &i : people) {cin >> i;}
for(int &i : money) {cin >> i;}
vector<int> leftover(1<<m, -1);
vector<int> people_covered(1<<m, -1);
leftover[0] = 0;
people_covered[0] = 0;
for(int s = 0; s < (1<<m); ++s){
for(int last = 0; last < m; ++last){
if(!(s&(1<<last))) continue;
int prev = s & ~(1<<last);
if(people_covered[prev]==-1) continue;
int new_amt = leftover[prev] + money[last];
int curr_target = people[people_covered[prev]];
if(new_amt < curr_target){
people_covered[s] = people_covered[prev];
leftover[s] = new_amt;
}else if(new_amt==curr_target){
people_covered[s] = people_covered[prev]+1;
leftover[s] = 0;
}
}
if(people_covered[s]==p){
cout << "YES\n";
return 0;
}
}
cout << "NO\n";
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... |