이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |