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"
#define pb push_back
#define vll vector<long long>
#define vb vector<bool>
#define vi vector<int>
#define vs vector<string>
#define vpii vector< pair<int, int> >
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vvi vector< vector<int> >
#define ld long double
#define mp make_pair
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;
const int MAXN = 2e5;
int MOD = 1e9+7;
int main() {
int people_num;
int note_num;
std::cin >> people_num >> note_num;
vector<int> people(people_num);
vector<int> banknotes(note_num);
for (int& p : people) {
std::cin >> p;
}
for (int& b : banknotes) {
std::cin >> b;
}
vector<int> leftover(1 << note_num, -1);
vector<int> people_covered(1 << note_num, -1);
leftover[0] = 0;
people_covered[0] = 0;
for (int s = 0; s < (1 << note_num); s++) {
for (int last = 0; last < note_num; last++) {
if ((s & (1 << last)) == 0) {
continue;
}
int prev = s & ~(1 << last);
if (people_covered[prev] == -1) {
continue;
}
int new_amt = leftover[prev] + banknotes[last];
// the salary of the current person we're going to try to pay
int curr_target = people[people_covered[prev]];
// if it's still not enough, just increment the leftover pile
if (new_amt < curr_target) {
people_covered[s] = people_covered[prev];
leftover[s] = new_amt;
}
/*
* or it's exactly right, in which case reset the leftover count
* and increment the covered amount
*/
else if (new_amt == curr_target) {
people_covered[s] = people_covered[prev] + 1;
leftover[s] = 0;
}
}
// we've covered all the people!
if (people_covered[s] == people_num) {
cout << "YES" << endl;
return 0;
}
}
cout << "NO" << endl;
}
# | 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... |