This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long int
using namespace std;
const int maxn = 1 << 21, inf = 1e18;
int n, m, sallary[21],money[21], cover[maxn], left_money[maxn];
int32_t main(){
// freopen("bank.in","r",stdin);
// freopen("bank.out","w",stdout);
ios::sync_with_stdio(0) ,cout.tie(0) ,cin.tie(0);
cin >> n >> m;
for(int i = 0 ;i < n; i++){
cin >> sallary[i];
}
for(int i = 0 ;i < m;i++){
cin >> money[i];
}
for(int i = 0 ; i <= (1 << m); i++){
cover[i] = -inf;
left_money[i] = -inf;
}
cover[0] = 0;
left_money[0] = 0;
for(int i = 0 ;i < (1 << m); i++){
int mask = i;
while(mask > 0){
int j = __builtin_ctz(mask);
int ghabli = i ^ (1 << j);
if(cover[ghabli] == -inf){
mask ^= (1 << j);
continue;
}
int now_money = left_money[ghabli] + money[j];
int want_money = sallary[cover[ghabli]];
if(now_money < want_money){
cover[i] = cover[ghabli];
left_money[i] = now_money;
}
else if(now_money == want_money){
cover[i] = cover[ghabli] + 1;
left_money[i] = 0;
}
mask ^= (1 << j);
}
if(cover[i] == n){
cout << "YES" << endl;
return 0;
}
}
cout << "NO" << endl;
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... |