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>
#include <algorithm>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<int> salaries(N);
vector<int> banknotes(M);
for (int i = 0; i < N; i++) {
cin >> salaries[i];
}
for (int i = 0; i < M; i++) {
cin >> banknotes[i];
}
// Sort banknotes in descending order for efficient matching
sort(banknotes.rbegin(), banknotes.rend());
// Try to match each salary with available banknotes
for (int i = 0; i < N; i++) {
int salary = salaries[i];
bool matched = false;
for (int j = 0; j < M; j++) {
if (banknotes[j] <= salary) {
salary -= banknotes[j];
banknotes[j] = 0; // Mark this banknote as used
}
if (salary == 0) {
matched = true;
break;
}
}
if (!matched) {
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << 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... |