이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |