# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
870841 | ljlkj | Bank (IZhO14_bank) | C++14 | 1 ms | 348 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;
int main(){
int n , m;
cin >> n >> m;
vector<int> persons(n);
vector<int> notes(m);
for(int i = 0; i < n; i++) cin >> persons[i];
for(int i = 0; i < m; i++) cin >> notes[i];
vector<pair<int , int>> dp(1<<m);
for(int s = 0; s < (1<<m); s++){
dp[s].first = -1;
dp[s].second = 0;
for(int b = 0; b < n; b++){
if(s&&(1<<b)){
int lastIndex = dp[s^(1<<b)].first;
int value = dp[s^(1<<b)].second;
if(notes[b] + value == persons[lastIndex]){
if(dp[s].first < lastIndex + 1){
dp[s].first = lastIndex + 1;
dp[s].second = 0;
}
}
else if(notes[b] + value < persons[lastIndex]){
if(dp[s].first < lastIndex){
dp[s].first = lastIndex;
dp[s].second = value + notes[b];
}
}
}
}
}
// cout << "test: " << dp[(1<<m) - 1].first << endl;
if(dp[(1<<m) - 1].first == n) 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... |