Submission #448304

#TimeUsernameProblemLanguageResultExecution timeMemory
448304LoboBank (IZhO14_bank)C++17
100 / 100
149 ms8592 KiB
#include <bits/stdc++.h> using namespace std; const long long INFll = (long long) 1e18 + 10; const int INFii = (int) 1e9 + 10; typedef long long ll; typedef int ii; typedef double dbl; #define endl '\n' #define sc second #define fr first #define mp make_pair #define pb push_back #define all(x) x.begin(), x.end() #define maxn 21 #define maxpow 2200000 ii n, m, a[maxn], b[maxn]; pair<ii,ii> dp[maxpow]; int main() { ios::sync_with_stdio(false); cin.tie(0); //freopen("in.in", "r", stdin); //freopen(".out", "w", stdout); cin >> n >> m; for(ii i = 0; i < n; i++) cin >> a[i]; for(ii i = 0; i < m; i++) cin >> b[i]; for(ii mask = 1; mask < (1<<m); mask++) { pair<ii,ii> ans = mp(0,0); for(ii j = 0; j < m; j++) { if((mask&(1<<j)) == 0) continue; ii i = dp[mask^(1<<j)].fr; ii x = dp[mask^(1<<j)].sc; if(b[j] + x == a[i]) ans = max(ans, mp(i+1,0)); else if(b[j] + x < a[i]) ans = max(ans, mp(i,b[j]+x)); } dp[mask] = ans; if(ans.fr == n) { cout << "YES" << endl; return 0; } } cout << "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...