Submission #1098399

#TimeUsernameProblemLanguageResultExecution timeMemory
1098399vjudge1Bank (IZhO14_bank)C++17
0 / 100
1 ms348 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...