# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
337888 | kutbilim_one | Bank (IZhO14_bank) | C++14 | 527 ms | 12012 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>
using namespace std;
#define endl '\n'
#define all(x) x.begin(), x.end()
#define int long long
signed main(){
ios_base::sync_with_stdio(false);
cin.tie();
int n, m;
cin >> n >> m;
vector<int> a(n), b(m);
for(int i = 0; i < n; i++) cin >> a[i];
for(int j = 0; j < m; j++) cin >> b[j];
int maxx = *max_element(all(a));
vector<int> pass[1 + maxx];
for(int bin = 1; bin < (1 << m); bin++){
int i = 0, sum = 0, temp = bin;
while(temp){
if(temp & 1) sum += b[i];
temp >>= 1;
i++;
}
if(sum <= maxx) pass[sum].push_back(bin);
}
vector< vector<bool> > dp(n, vector<bool> (1 << m, false));
for(int i = 0; i < pass[a[0]].size(); i++){
dp[0][pass[a[0]][i]] = true;
}
for(int i = 1; i < n; i++){
int good = 0;
for(int bin = 0; bin < (1 << m); bin++){
if(!dp[i-1][bin]) continue;
for(auto last : pass[a[i]])
if(!(last & bin)) dp[i][last|bin] = good = true;
}
if(!good) break;
}
bool ans = false;
for(int i = 0; !ans && i < (1 << m); i++){
if(dp[n-1][i]) ans = true;
}
if(ans) cout << "YES";
else cout << "NO";
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... |