Submission #1088395

#TimeUsernameProblemLanguageResultExecution timeMemory
1088395michifiedBank (IZhO14_bank)C++17
100 / 100
95 ms8824 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; const ll mod = 1e9 + 7; struct elem_t { int met, rem; }; int main() { // ifstream cin("valleys.in"); // ofstream cout("valleys.out"); int n, m, i, j; cin >> n >> m; vector<int> sal(n), note(m); for (i = 0; i < n; i++) cin >> sal[i]; for (i = 0; i < m; i++) cin >> note[i]; if (n > m) { cout << "NO"; return 0; } int M = 1 << m; vector<elem_t> dp(M, {0, 0}); elem_t newe; int res; for (i = 1; i < M; i++) { for (j = 0; j < m; j++) { if (not (i & (1 << j))) continue; res = dp[i - (1 << j)].rem + note[j]; if (res > sal[dp[i - (1 << j)].met]) continue; else if (res == sal[dp[i - (1 << j)].met]) { newe.met = dp[i - (1 << j)].met + 1; newe.rem = 0; } else { newe.met = dp[i - (1 << j)].met; newe.rem = res; } if (newe.met == n) { cout << "YES"; return 0; } if (newe.met > dp[i].met) dp[i] = newe; else if (newe.met == dp[i].met) dp[i].rem = max(dp[i].rem, newe.rem); } } cout << "NO"; 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...