Submission #961548

#TimeUsernameProblemLanguageResultExecution timeMemory
961548doducanhBank (IZhO14_bank)C++14
100 / 100
102 ms8560 KiB
#include <bits/stdc++.h> using namespace std; int leftovers[(1<<20)+7]; int people_cover[(1<<20)+7]; int a[25],b[25]; int n,m; main() { cin>>n>>m; for(int i=0;i<n;i++)cin>>a[i]; for(int i=0;i<m;i++)cin>>b[i]; for(int mask=1;mask<(1<<m);mask++)people_cover[mask]=-1; people_cover[0]=0; leftovers[0]=0; for(int mask=1;mask<(1<<m);mask++){ for(int i=0;i<=m;i++){ if((mask>>i)&1){ int prev=(mask^(1<<i)); if(people_cover[prev]==-1)continue; int amt=leftovers[prev]+b[i]; if(amt<a[people_cover[prev]]){ leftovers[mask]=amt; people_cover[mask]=people_cover[prev]; } else if(amt==a[people_cover[prev]]){ leftovers[mask]=0; people_cover[mask]=people_cover[prev]+1; } } } if(people_cover[mask]==n){ cout<<"YES"; return 0; } } cout<<"NO"; return 0; }

Compilation message (stderr)

bank.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    8 | main()
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...