Submission #676157

#TimeUsernameProblemLanguageResultExecution timeMemory
676157hxy123123Bank (IZhO14_bank)C++14
100 / 100
109 ms8532 KiB
#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]=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)

bank.cpp: In function 'void solve()':
bank.cpp:7:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |  scanf("%d%d",&n,&m);
      |  ~~~~~^~~~~~~~~~~~~~
bank.cpp:8:29: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |  for(int i=1;i<=n;i++) scanf("%d",&a[i]);
      |                        ~~~~~^~~~~~~~~~~~
bank.cpp:9:29: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |  for(int i=0;i<m;i++)  scanf("%d",&b[i]);
      |                        ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...