This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |