Submission #528177

#TimeUsernameProblemLanguageResultExecution timeMemory
528177CursedCodeBank (IZhO14_bank)C++14
100 / 100
130 ms8516 KiB
#include<bits/stdc++.h> using namespace std; int covered[(1<<20)] = {-1},leftover[(1<<20)] = {-1}; int main(){ int n,m,i,j,a[21],b[21]; cin >> n >> m; for(i = 0;i < n;i++){ cin >> a[i]; } sort(a,a+n); for(i = 0;i < m;i++){ cin >> b[i]; } leftover[0] = 0; covered[0] = 0; for(i = 1;i < (1 << m);i++){ for(j = 0;j < m;j++){ if(i & (1 << j)){ int ih = i ^ (1 << j); if(leftover[ih] + b[j] < a[covered[ih]]){ if(covered[i] <= covered[ih]){ leftover[i] = leftover[ih] + b[j]; covered[i] = covered[ih]; } } if(leftover[ih] + b[j] == a[covered[ih]]){ if(covered[i] <= covered[ih] + 1){ leftover[i] = 0; covered[i] = covered[ih] + 1; } } //cout << i << ' ' << covered[i] << ' ' << leftover[i] << ' ' << j << endl; } } if(covered[i] == n){ cout << "YES"; return 0; } } cout << "NO"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...