제출 #974190

#제출 시각아이디문제언어결과실행 시간메모리
974190Art_ogo은행 (IZhO14_bank)C++17
100 / 100
102 ms8788 KiB
#include <bits/stdc++.h> #define ll long long #define fi first #define se second #define ve vector #define all(x) x.begin(), x.end() #define pb(x) push_back(x) using namespace std; mt19937 rnd; typedef pair<ll, ll> pll; typedef pair<int, int> pii; void solve(){ int n, m; cin >> n >> m; ve<int> a(n); ve<int> b(m); for(auto& i : a) cin >> i; for(auto& j : b) cin >> j; ve<int> cur(1 << m, -1); ve<int> lefts(1 << m, -1); cur[0] = lefts[0] = 0; for(int i = 1; i < (1 << m); i++){ for(int j = 0; j < m; j++){ if(!((i >> j) & 1)) continue; int prev = i ^ (1 << j); if(cur[prev] == -1) continue; int li = lefts[prev] + b[j]; if(li > a[cur[prev]]) continue; if(li == a[cur[prev]]){ cur[i] = cur[prev] + 1; lefts[i] = 0; } else{ cur[i] = cur[prev]; lefts[i] = li; } if(cur[i] == n){ cout << "YES"; return; } } } cout << "NO"; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); int T = 1; // cin >> T; while(T--){ solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...