Submission #316943

#TimeUsernameProblemLanguageResultExecution timeMemory
316943mihai145Jelly Flavours (IOI20_jelly)C++14
24 / 100
205 ms78584 KiB
#include "jelly.h" #include <vector> #include <algorithm> const int NMAX = 2000; const int XMAX = 10000; const int INF = 10 * XMAX; std::vector < std::pair <int, int> > pairs; int dp[NMAX + 2][XMAX + 2]; int find_maximum_unique(int x, int y, std::vector<int> a, std::vector<int> b) { int n = (int)a.size(); for(int i = 0; i < n; i++) pairs.push_back({a[i], b[i]}); sort(pairs.begin(), pairs.end()); for(int i = 0; i <= n; i++) for(int bugA = 0; bugA <= x; bugA++) dp[i][bugA] = INF; dp[0][0] = 0; for(int i = 0; i < n; i++) for(int bugA = 0; bugA <= x; bugA++) if(dp[i][bugA] <= y) { ///cumpar i + 1 din A if(bugA + pairs[i].first <= x) dp[i + 1][bugA + pairs[i].first] = std::min(dp[i + 1][bugA + pairs[i].first], dp[i][bugA]); ///cumpar i + 1 din B if(dp[i][bugA] + pairs[i].second <= y) dp[i + 1][bugA] = std::min(dp[i + 1][bugA], dp[i][bugA] + pairs[i].second); } std::vector <int> sufb; int sol = 0; for(int i = n; i >= 0; i--) { int minY = INF; for(int bugA = 0; bugA <= x; bugA++) minY = std::min(minY, dp[i][bugA]); if(minY <= y) { int placed = i; ///pref if(i + 1 <= n) sufb.push_back(pairs[i].second); sort(sufb.begin(), sufb.end()); int remBudget = y - minY; for(auto it : sufb) if(remBudget >= it) { remBudget -= it; placed++; } else break; sol = std::max(sol, placed); } } return sol; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...