Submission #1001392

#TimeUsernameProblemLanguageResultExecution timeMemory
1001392toan2602Bank (IZhO14_bank)C++14
0 / 100
1 ms604 KiB
#include<bits/stdc++.h> using namespace std; #define int long long void solve() { int n, m; cin >> n >> m; vector<int> a(n), b(m); vector<pair<int, int>> dp(1<<m); for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >> b[i]; for (int mask = 0; mask < (1<<n); mask++) { for (int j = 0; j < mask; j++) { if(mask >> j & 1) { int mask2 = mask ^ (1 << j); int sum = dp[mask2].second; sum += b[j]; if(sum == a[dp[mask2].first + 1]) dp[mask] = {dp[mask2].first+1, 0}; else if(sum < a[dp[mask2].first+1]) dp[mask] = {dp[mask2].first, sum}; } } if(dp[mask].first == n-1) {cout << "YES\n"; return;} } cout << "NO"; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; 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...