# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1088572 | vjudge1 | Bank (IZhO14_bank) | C++17 | 1 ms | 856 KiB |
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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define vi vector<int>
#define vll vector<ll>
#define MAX 1e9
int dp[1001][101];
bool used[101];
vi notas;
bool solve(int sum, int idx, int m) {
if (sum == 0) return true;
if (idx >= m || sum < 0) return false;
if (dp[sum][idx] != -1) return dp[sum][idx];
bool pegar = false;
if (!used[idx] && sum >= notas[idx]) {
used[idx] = true;
pegar = solve(sum - notas[idx], 0, m);
if (!pegar) used[idx] = false;
}
bool n_pegar = solve(sum, idx + 1, m);
return dp[sum][idx] = pegar || n_pegar;
}
int main() {
int n, m;
cin >> n >> m;
vector<int> salarios(n);
notas.resize(m);
for (int i = 0; i < n; i++) {
cin >> salarios[i];
}
for (int i = 0; i < m; i++) {
cin >> notas[i];
}
for (int i = 0; i < n; i++) {
memset(dp, -1, sizeof(dp));
if (!solve(salarios[i], 0, m)) {
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
return 0;
}
Compilation message (stderr)
# | 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... |