Submission #1089496

#TimeUsernameProblemLanguageResultExecution timeMemory
1089496vjudge1Bank (IZhO14_bank)C++98
100 / 100
90 ms8656 KiB
#include <iostream>
#include <vector>
#include <climits>
using namespace std;

int main() {
    int n, m;
    
    // Leitura de 'n' e 'm'
    cin >> n >> m;

    vector<int> valores(n), notas(m);

    // Leitura dos valores
    for (int i = 0; i < n; i++) {
        cin >> valores[i];
    }

    // Leitura das notas
    for (int i = 0; i < m; i++) {
        cin >> notas[i];
    }

    vector<int> residual(1 << m, INT_MIN);
    vector<int> cobertos(1 << m, INT_MIN);

    residual[0] = 0;
    cobertos[0] = 0;

    bool possivel = true;

    for (int s = 0; s < (1 << m); s++) {
        for (int p = 0; p < m; p++) {
            if ((s & (1 << p)) == 0) continue;

            int ant = s & ~(1 << p);

            if (cobertos[ant] == INT_MIN) continue;

            int novo = residual[ant] + notas[p];

            if (cobertos[ant] < n) {
                int alvo = valores[cobertos[ant]];

                if (novo < alvo) {
                    cobertos[s] = cobertos[ant];
                    residual[s] = novo;
                } else if (novo == alvo) {
                    cobertos[s] = cobertos[ant] + 1;
                    residual[s] = 0;
                }
            }
        }

        if (cobertos[s] == n) {
            possivel = false;
        }
    }

    if (!possivel) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << 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...