Submission #1034432

#TimeUsernameProblemLanguageResultExecution timeMemory
1034432ArthuroWichBank (IZhO14_bank)C++17
100 / 100
87 ms17116 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int void solve() { int n, m; cin >> n >> m; vector<int> a(n), b(m); vector<pair<int, int>> dp(1<<m, {-1, -1}); for (int &x : a) { cin >> x; } for (int &x : b) { cin >> x; } dp[0] = {0, 0}; for (int i = 1; i < 1 << m; i++) { for (int j = 0; j < m;j++) { if (!(i&(1<<j))) { continue; } int x = i^(1<<j); if (dp[x].second == -1) { continue; } if (dp[x].second+b[j] < a[dp[x].first]) { dp[i].first = dp[x].first; dp[i].second = dp[x].second+b[j]; } else if (dp[x].second+b[j] == a[dp[x].first]) { dp[i].first = dp[x].first+1; dp[i].second = 0; } } if (dp[i].first == n) { cout << "YES" << endl; return; } } cout << "NO" << endl; } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); int t; t = 1; while(t--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...