# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
657469 | marche | Bank (IZhO14_bank) | C++14 | 108 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>
using namespace std;
#define fr first
#define sc second
pair<int,int> dp[(1 <<20)];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n,m;
cin >> n >> m;
vector<int>a(n);
vector<int>b(m);
for (int i= 0 ; i<n; i++)cin >> a[i];
for(int i = 0; i<m; i++)cin >> b[i];
// let S be a binary number < 2^n which indicates which people have already received salary
// dp[s][]
// look at problem from another perspective
// let S be a binary number indicating which bank notes have been taken
// dp[s][i] = max number of people with S notes taken if i people have been considered
// dp[s] inidcates how many people can be payed if S = {1,1,1,1,0,0,1,0,1..,0}have been taken
memset(dp, -1, sizeof(dp));
dp[0] = {0,0};
for (int i = 0; i<(1 << m); i++){
for (int j = 0; j<m; j++){
if ((1 << j) & i == 0)continue;
int p = i ^ (1 << j);
if (dp[p].fr == -1)continue;
int nx = dp[p].sc + b[j];
if (nx == a[dp[p].fr]){
dp[i].fr = dp[p].fr + 1;
dp[i].sc = 0;
}else if (nx < a[dp[p].fr]){
dp[i].fr = dp[p].fr;
dp[i].sc = nx;
}
}
if (dp[i].fr == n){
cout<<"YES"<<endl;
return 0;
}
}
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... |