# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
883236 | cemil1234 | Bank (IZhO14_bank) | C++17 | 109 ms | 16876 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 ull unsigned long long
void solve(){
long long n,m,x;
cin>>n>>m;
vector<long long>pp(n),bn(m);
for(long long i = 0;i<n;i++){
cin>>pp[i];
}
for(long long i = 0;i<m;i++){
cin>>bn[i];
}
vector<long long>cnt(1<<m,-1),left(1<<m,-1);
cnt[0] = 0;
left[0] = 0;
for(long long i = 0;i<(1<<m);i++){
for(long long j = 0;j<m;j++){
if((i&(1<<j)) == 0){
continue;
}
long long pre = i^(1<<j);
if(cnt[pre] == -1){
continue;
}
long long nleft = left[pre]+bn[j];
if(nleft == pp[cnt[pre]]){
left[i] = 0;
cnt[i] = cnt[pre]+1;
}
else if(nleft<pp[cnt[pre]]){
left[i] = nleft;
cnt[i] = cnt[pre];
}
}
if(cnt[i] == n){
cout<<"YES\n";
return;
}
}
cout<<"NO\n";
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
//cin>>t;
while(t--){
solve();
}
}
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... |