# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
716633 | nonono | Bank (IZhO14_bank) | C++14 | 72 ms | 8532 KiB |
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 SZ(x) (int)(x.size())
using namespace std;
const int mxN = 20;
int n, m, a[mxN], b[mxN];
pair<int, int> dp[1 << mxN];
signed main(){
#define name "bank"
if(fopen(name".inp", "r")){
freopen(name".inp", "r", stdin);
freopen(name".out", "w", stdout);
}
ios_base::sync_with_stdio(); cin.tie(); cout.tie();
cin >> n >> m;
for(int i = 0; i < n; i ++) cin >> a[i];
for(int i = 0; i < m; i ++) cin >> b[i];
for(int mask = 0; mask < (1 << m); mask ++)
dp[mask] = {-1, 0};
dp[0] = {0, 0};
for(int mask = 0; mask < (1 << m); mask ++){
for(int x = mask; x > 0; x ^= x & (- x)){
int i = __builtin_ctz(x & (- x));
int nmask = mask ^ (1 << i);
if(dp[nmask].first == -1) continue ;
int j = dp[nmask].first;
if(dp[nmask].second + b[i] < a[j]) dp[mask] = {j, dp[nmask].second + b[i]};
if(dp[nmask].second + b[i] == a[j]) dp[mask] = {j + 1, 0};
if(dp[mask].first == n){
cout << "YES\n";
exit(0);
}
}
}
cout << "NO\n";
return 0;
}
Compilation message (stderr)
# | 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... |