Submission #1231930

#TimeUsernameProblemLanguageResultExecution timeMemory
1231930djsksbrbfBank (IZhO14_bank)C++20
100 / 100
96 ms16848 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair <int, int> pii; #define fi first #define se second #define pb push_back const int MOD = 1e9 + 7; const int MAX = (1ll << 20) + 5; signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; int a[n + 1]; int b[m]; for(int i = 1 ; i <= n ; i++)cin >> a[i]; for(int i = 0 ; i < m ; i++)cin >> b[i]; ll dp[(1ll << m) + 5][2];memset(dp, -1, sizeof(dp)); // 0 is the fulfilled, 1 is the remaining from the last one dp[0][0] = 1; dp[0][1] = 0; bool ans = 0; for(int i = 0 ; i <= (1ll << m) - 1 ; i++){ for(int j = 0 ; j < m ; j++){ if((i & (1ll << j)) == 0)continue; ll prev = (i^ (1ll <<j)); if(dp[prev][0] == -1)continue; ll cur = dp[prev][1] + b[j]; ll needed = a[dp[prev][0]]; if(cur < needed){ dp[i][0] = dp[prev][0]; dp[i][1] = cur; } else if(cur == needed){ dp[i][0] = dp[prev][0] + 1; dp[i][1] = 0; } } if(dp[i][0] == n + 1){ ans = 1; break; } } cout << (ans ? "YES" : "NO") << endl; 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...