Submission #434266

#TimeUsernameProblemLanguageResultExecution timeMemory
434266madlogicJelly Flavours (IOI20_jelly)C++17
0 / 100
77 ms452 KiB
#include "jelly.h" #include <bits/stdc++.h> using namespace std; int find_maximum_unique(int x, int y, std::vector<int> a, std::vector<int> b) { int n = (int) a.size(); vector<pair<int, int>> jellies(n); for (int i = 0; i < n; i++) { jellies[i].first = a[i]; jellies[i].second = b[i]; } sort(jellies.begin(), jellies.end()); vector<int> pref(n), suff(n); for (int i = 0; i < n; i++) { vector<int> v; for (int j = 0; j <= i; j++) { v.push_back(jellies[j].second); } sort(v.begin(), v.end()); int tmp = y; int cnt = 0; for (int& cost : v) { if (tmp - cost >= 0) { ++cnt; tmp -= cost; } } pref[i] = cnt; } for (int i = n - 1; i >= 0; i--) { vector<int> v; for (int j = i; j < n; j++) { v.push_back(jellies[j].second); } sort(v.begin(), v.end()); int tmp = y; int cnt = 0; for (int& cost : v) { if (tmp - cost >= 0) { ++cnt; tmp -= cost; } } suff[i] = cnt; } int res = 0; for (int i = 0; i < n; i++) { int sum = 0; for (int j = i; j < n; j++) { if (sum + jellies[j].first > x) { break; } sum += jellies[j].first; res = max(res, (j - i + 1) + (i > 0 ? pref[i - 1] : 0) + (j + 1 < n ? suff[j + 1] : 0)); } } return res; }
#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...