#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool canPaySalary(int salary, vector<int>& banknotes) {
int maxSum = 1000; // Maximum possible salary
vector<bool> dp(maxSum + 1, false);
dp[0] = true;
for (int b : banknotes) {
for (int j = maxSum; j >= b; --j) {
if (dp[j - b]) dp[j] = true;
}
}
return dp[salary];
}
bool canPayAllSalaries(vector<int>& salaries, vector<int>& banknotes) {
for (int salary : salaries) {
if (!canPaySalary(salary, banknotes)) return false;
// Deduct used banknotes for this salary
vector<int> temp;
for (int b : banknotes) {
if (salary >= b) {
salary -= b;
} else {
temp.push_back(b);
}
}
banknotes = temp;
}
return true;
}
int main() {
int n, m;
cin >> n >> m;
vector<int> salaries(n), banknotes(m);
for (int i = 0; i < n; ++i) cin >> salaries[i];
for (int i = 0; i < m; ++i) cin >> banknotes[i];
if (canPayAllSalaries(salaries, banknotes)) {
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... |