# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1112885 | luvna | Bank (IZhO14_bank) | C++14 | 2 ms | 2584 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 all(v) v.begin(), v.end()
#define endl "\n"
using namespace std;
const int N = 21;
int n, m;
int a[N], b[N];
int dp[(1 << 21)+15];
int sum[(1 << 21)+15];
void solve(){
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 i = 1; i < (1 << m); i++) dp[i] = sum[i] = -1;
for(int mask = 0; mask < (1 << m); mask++){
for(int i = 0; i < m; i++){
if(mask >> i & 1 && dp[mask ^ (1 << i)] != -1){
int prev_mask = mask ^ (1 << i);
int cur_sum = sum[prev_mask] + b[i];
int target = a[dp[prev_mask]];
if(cur_sum < target){
dp[mask] = dp[prev_mask];
sum[mask] = cur_sum;
}
else if(cur_sum == target){
dp[mask]++;
sum[mask] = 0;
}
}
}
if(dp[mask] == n){
cout << "YES" << endl;
return;
}
}
cout << "NO" << endl;
}
signed main(){
ios_base::sync_with_stdio(NULL);
cin.tie(0); cout.tie(0);
#define task "task"
if(fopen(task".INP", "r")){
freopen(task".INP", "r", stdin);
freopen(task".OUT", "w", stdout);
}
int t; t = 1; //cin >> t;
while(t--) solve();
}
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... |