제출 #895740

#제출 시각아이디문제언어결과실행 시간메모리
895740Kodik은행 (IZhO14_bank)C++17
100 / 100
97 ms8788 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define ff first #define ss second int main(){ ios_base::sync_with_stdio(false), cin.tie(NULL); // freopen("bank.in", "r", stdin); // freopen("bank.out", "w", stdout); int p, m; cin >> p >> m; vector<int> people(p); vector<int> money(m); for(int &i : people) {cin >> i;} for(int &i : money) {cin >> i;} vector<int> leftover(1<<m, -1); vector<int> people_covered(1<<m, -1); leftover[0] = 0; people_covered[0] = 0; for(int s = 0; s < (1<<m); ++s){ for(int last = 0; last < m; ++last){ if(!(s&(1<<last))) continue; int prev = s & ~(1<<last); if(people_covered[prev]==-1) continue; int new_amt = leftover[prev] + money[last]; int curr_target = people[people_covered[prev]]; if(new_amt < curr_target){ people_covered[s] = people_covered[prev]; leftover[s] = new_amt; }else if(new_amt==curr_target){ people_covered[s] = people_covered[prev]+1; leftover[s] = 0; } } if(people_covered[s]==p){ cout << "YES\n"; return 0; } } cout << "NO\n"; 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...