Submission #1022236

#TimeUsernameProblemLanguageResultExecution timeMemory
1022236ivazivaBank (IZhO14_bank)C++14
19 / 100
83 ms16828 KiB
#include <bits/stdc++.h> using namespace std; #define MAXN 20 long long n,m; long long a[MAXN],b[MAXN]; long long preostalo[1<<MAXN]; long long pokriveno[1<<MAXN]; int main() { cin>>n>>m; for (long long i=1;i<=n;i++) cin>>a[i]; for (long long i=1;i<=m;i++) cin>>b[i]; for (long long i=1;i<(1<<MAXN);i++) preostalo[i]=pokriveno[i]=-1; preostalo[0]=pokriveno[0]=0; for (long long suma=0;suma<(1<<m);suma++) { for (long long poslednji=0;poslednji<m;poslednji++) { if ((suma&(1<<poslednji))==0) continue; long long prethodni=suma & ~(1<<poslednji); if (pokriveno[prethodni]==-1) continue; long long noviostatak=preostalo[prethodni]+b[poslednji]; long long plata=a[pokriveno[prethodni]+1]; if (noviostatak<plata) { pokriveno[suma]=pokriveno[prethodni]; preostalo[suma]=noviostatak; } else if (noviostatak==plata) { pokriveno[suma]=pokriveno[prethodni]+1; preostalo[suma]=0; } } if (pokriveno[suma]==n) {cout<<"YES"<<endl;return 0;} } cout<<"NO"<<endl;return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...