# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
672490 | dsyz | Bank (IZhO14_bank) | C++17 | 125 ms | 16768 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;
using ll = long long;
#define MAXN (1000005)
int main() {
ios_base::sync_with_stdio(false);cin.tie(0);
ll N,M;
cin>>N>>M;
ll A[N];
ll B[M];
for(ll i = 0;i < N;i++){
cin>>A[i];
}
for(ll i = 0;i < M;i++){
cin>>B[i];
}
bool ok = 0;
pair<ll,ll> dp[1ll<<M]; //maximum prefix of A done by bitmask, remaining sum of B not used
memset(dp,0,sizeof(dp));
for(ll i = 0;i < (1ll << M);i++){
for(ll j = 0;j < M;j++){
if(!((i >> j) & 1)){
continue;
}
ll k = i ^ (1 << j); //previous state without jth banknote
pair<ll,ll> res = dp[k];
res.second += B[j];
if(A[res.first] == res.second){
res.first++;
res.second = 0;
}
dp[i] = max(dp[i],res);
if(dp[i].first >= N) ok = 1;
}
}
if(ok){
cout<<"YES"<<'\n';
}else{
cout<<"NO"<<'\n';
}
}
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... |