Submission #679608

#TimeUsernameProblemLanguageResultExecution timeMemory
67960842kangarooBank (IZhO14_bank)C++17
100 / 100
105 ms16804 KiB
// // Created by 42kangaroo on 08/01/2023. // #include "bits/stdc++.h" using namespace std; #define int long long signed main() { int n, m; cin >> n >> m; vector<int> a(n); vector<int> b(m); for (int i = 0; i < n; ++i) { cin >> a[i]; } for (int i = 0; i < m; ++i) { cin >> b[i]; } vector<pair<int,int>> dp(1 << m, {-1, -1}); dp[0] = {0, a[0]}; for (int i = 1; i < 1 << m; ++i) { for (int j = 0; j < m; ++j) { if (i & 1 << j) { if (dp[i^(1<<j)].first != -1) { if (dp[i^(1<<j)].second > b[j]) { dp[i]= {dp[i^(1<<j)].first, dp[i^(1<<j)].second - b[j]}; } if (dp[i^(1<<j)].second == b[j]) { if (dp[i^(1<<j)].first == n - 1) { cout << "YES\n"; return 0; } dp[i] = {dp[i^(1<<j)].first+1, a[dp[i^(1<<j)].first+1]}; } } } } } cout << "NO\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...