# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
676156 | hxy123123 | Bank (IZhO14_bank) | C++14 | 5 ms | 8500 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;
const int N=(1<<20);
int dp[N],l[N];
int n,m,a[21],b[21];
void solve(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
for(int i=0;i<m;i++) scanf("%d",&b[i]);
memset(dp,-1,sizeof dp);
memset(l,-1,sizeof l);
dp[0]=0;
l[0]=0;
for(int i=0;i<(1<<m);i++){
for(int j=0;j<m;j++){
if((i&(1<<j))==0) continue;
int k=i-(1<<j);
if(dp[k]==-1) continue;
if(l[k]+b[j]<a[dp[k]+1]){
dp[i]=max(dp[k],dp[i]);
l[i]=a[dp[k]+1]-l[k]-b[j];
}
else if(l[k]+b[j]==a[dp[k]+1]){
l[i]=0;
dp[i]=max(dp[i],dp[k]+1);
}
if(dp[i]==n){
cout<<"YES"<<endl;
return ;
}
}
}
cout<<"NO"<<endl;
return ;
}
int main(){
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... |