이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |