Submission #1136306

#TimeUsernameProblemLanguageResultExecution timeMemory
1136306abel2008Bank (IZhO14_bank)C++20
0 / 100
0 ms324 KiB
#include <iostream> #include <fstream> #include <utility> using namespace std; ifstream fin("bank.in"); ofstream fout("bank.out"); int salary[25],notes[25],n,m; pair<int,int> dp[1<<20]; // {completed salaries,currsum} pair<int,int> calc(pair<int,int> pi,int note) { int crtsalary = pi.first+1; int crtsum = pi.second; if (crtsum+note==salary[crtsalary]) { return {pi.first+1,0}; } else if (crtsum+note<salary[crtsalary]) { return {pi.first,pi.second+note}; } else { return {-1,-1}; } } int main() { fin>>n>>m; for (int i = 1;i<=n;++i) fin>>salary[i]; for (int i = 1;i<=m;++i) fin>>notes[i]; for (int i = 0;i<(1<<m);++i) { dp[i] = {-1,-1}; } dp[0] = {0,0}; for (int mask = 1;mask<(1<<m);++mask) { for (int j = 0;j<m;++j) { if (mask&(1<<j)&&dp[mask-(1<<j)].first!=-1) { dp[mask] = max(calc(dp[mask-(1<<j)],notes[j+1]),dp[mask]); } } if (dp[mask].first==n) { fout<<"YES"; return 0; } } fout<<"NO"; 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...