Submission #1013073

#TimeUsernameProblemLanguageResultExecution timeMemory
1013073aufanBank (IZhO14_bank)C++17
100 / 100
82 ms16860 KiB
#include <bits/stdc++.h> #define int long long #define fi first #define se second using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; vector<int> b(m); for (int i = 0; i < m; i++) cin >> b[i]; vector<pair<int, int>> dp(1 << m, {-1, -1}); dp[0] = {0, 0}; for (int mask = 1; mask < (1 << m); mask++) { for (int i = 0; i < m; i++) { if (mask >> i & 1) { auto [j, x] = dp[mask ^ (1 << i)]; if (j == -1) continue; if (x + b[i] < a[j]) dp[mask] = {j, x + b[i]}; else if (x + b[i] == a[j]) dp[mask] = {j + 1, 0}; } } if (dp[mask].fi == n) { cout << "YES" << '\n'; return 0; } } cout << "NO" << '\n'; 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...