제출 #974053

#제출 시각아이디문제언어결과실행 시간메모리
974053Art_ogo은행 (IZhO14_bank)C++17
19 / 100
76 ms8540 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++){ int mxi = -1; for(int j = 0; j < m; j++){ if(((i >> j) & 1) && (mxi == -1 || cur[i ^ (1 << j)] > cur[mxi])) mxi = j; } if(mxi == -1) continue; cur[i] = cur[i ^ (1 << mxi)]; lefts[i] = lefts[i ^ (1 << mxi)] + b[mxi]; if(lefts[i] > a[cur[i]]){ cur[i] = lefts[i] = -1; continue; } if(lefts[i] == a[cur[i]]){ cur[i]++; lefts[i] = 0; } 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...