제출 #681920

#제출 시각아이디문제언어결과실행 시간메모리
681920Markomafko972은행 (IZhO14_bank)C++14
100 / 100
123 ms8616 KiB
#include <bits/stdc++.h> #define X first #define Y second #define pb push_back #define pii pair<int, int> typedef long long ll; using namespace std; const int MOD = 1e9 + 7; const ll INF = 1e18; const int OFF = (1 << 20); int n, m; int a[22]; int b[22]; pair<int, int> dp[(1 << 20)+5]; int main () { ios_base::sync_with_stdio(false); cin.tie(0); 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 mask = 0; mask < (1 << m); mask++) { int pos = dp[mask].X; int kol = dp[mask].Y; if (pos == n) { cout << "YES"; return 0; } for (int i = 0; i < m; i++) { if ((mask&(1 << i)) == 0) { if (kol+b[i] > a[pos]) continue; if (kol+b[i] == a[pos]) dp[mask|(1 << i)] = max(dp[mask|(1 << i)], {pos+1, 0}); else dp[mask|(1 << i)] = max(dp[mask|(1 << i)], {pos, kol+b[i]}); } } } cout << "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...