Submission #554581

#TimeUsernameProblemLanguageResultExecution timeMemory
554581rafatoaBank (IZhO14_bank)C++17
100 / 100
149 ms16744 KiB
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; #define int ll #define double ld const int inf = 2e9; const int INF = 4e18; const int mod = 1e9+7; const int mx = 200001; #define F first #define S second #define vi vector<int> #define vvi vector<vi> #define pi pair<int, int> #define vpi vector<pi> #define vb vector<bool> #define pb push_back #define read(a) for(auto &x:a) cin >> x; #define print(a) for(auto x:a) cout << x << " "; cout << "\n"; #define ppb pop_back signed main(){ ios::sync_with_stdio(0); cin.tie(0); // #ifndef ONLINE_JUDGE // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); // #endif int n, m; cin >> n >> m; vi a(n), b(m); read(a); read(b); vpi best(1<<m, {0, 0}); for(int s=1; s<(1<<m); s++){ for(int t=0; t<m; t++){ if(!(s&(1<<t))) continue; pi option = best[s^(1<<t)]; if(best[s^(1<<t)].S + b[t] < a[best[s^(1<<t)].F]){ option.S = best[s^(1<<t)].S + b[t]; }else if(best[s^(1<<t)].S + b[t] == a[best[s^(1<<t)].F]){ option.F++; option.S = 0; } best[s] = max(best[s], option); } } for(auto x:best){ if(x.F == 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...