제출 #821810

#제출 시각아이디문제언어결과실행 시간메모리
821810OAleksa은행 (IZhO14_bank)C++14
100 / 100
105 ms8544 KiB
#include <bits/stdc++.h> #define f first #define s second using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int tt = 1; //cin >> tt; while(tt--) { int n, m; cin >> n >> m; vector<int> a(n), b(m); for(int i = 0;i < n;i++) cin >> a[i]; for(int i = 0;i < m;i++) cin >> b[i]; bool ok = false; vector<int> dp(1 << m, -1), o(1 << m); dp[0] = 0; for(int mask = 1;mask < (1 << m);mask++) { for(int i = 0;(1 << i) <= mask;i++) { if(!(mask & (1 << i))) continue; int s = mask ^ (1 << i); if(dp[s] == -1) continue; int sm = o[s] + b[i]; int sl = a[dp[s]]; if(sm < sl) { dp[mask] = dp[s]; o[mask] = sm; } else if(o[s] + b[i] == sl) { dp[mask] = max(dp[mask], dp[s] + 1); o[mask] = 0; } } ok |= (dp[mask] == n); } cout << (ok ? "YES" : "NO"); } 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...