Submission #881237

#TimeUsernameProblemLanguageResultExecution timeMemory
881237__Davit__Bank (IZhO14_bank)C++17
100 / 100
100 ms8808 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define ff first #define ss second #define pb push_back #define vr(v) v.begin(),v.end() #define rv(v) v.rbegin(),v.rend() #define Code ios_base::sync_with_stdio(false); #define By cin.tie(NULL); #define Davit cout.tie(NULL); using namespace std; //#include "algo/debug.h" //mt19937 myrand(chrono::steady_clock::now().time_since_epoch().count()); //mt19937_64 myrand(373); //mt19937 myrand(373); const int N = 20, M = (1 << N); int a[N], b[N]; pair<int, int> dp[M]; int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < m; ++i) cin >> b[i]; for (int i = 1; i < M; ++i) dp[i] = {-1, 0}; for (int mask = 1; mask < (1 << m); mask++) { for (int i = 0; i < m; i++) { if ((mask >> i) & 1) { pair<int, int> dpj = dp[mask ^ (1 << i)]; if (dpj.ff == -1)continue; if (dpj.ss + b[i] < a[dpj.ff]) { dp[mask] = {dpj.ff, dpj.ss + b[i]}; } else if (dpj.ss + b[i] == a[dpj.ff]) { dp[mask] = {dpj.ff + 1, 0}; } } } if (dp[mask].ff == n) { cout << "YES" << endl; return 0; } } 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...