# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
569509 | penguin133 | Bank (IZhO14_bank) | C++14 | 163 ms | 16704 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 int long long
pair<int, int> dp[2000005];
int A[25], B[25];
main(){
int n,m;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=0;i<(1<<m);i++){
dp[i] = make_pair(0, 0);
for(int j=0;j<m;j++){
if(!(i >> j & 1))continue;
int k = i^(1 << j);
pair<int, int> ans = dp[k];
ans.second += B[j];
if(A[ans.first] == ans.second){
ans.first++;
ans.second = 0;
}
dp[i] = max(dp[i], ans);
}
}
for(int i=0;i<(1<<m);i++){
if(dp[i].first == n){
cout << "YES";
return 0;
}
}
cout << "NO";
}
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... |