#include "festival.h"
#include <bits/stdc++.h>
using namespace std;
bool comp(pair<int, pair<int, int>> a, pair<int, pair<int, int>> b) {
return (long long)a.second.first * a.second.second * b.second.second + (long long)b.second.first * b.second.second <
(long long)b.second.first * a.second.second * b.second.second + (long long)a.second.first * a.second.second;
}
std::vector<int> max_coupons(int A, std::vector<int> P, std::vector<int> T) {
vector<pair<int, pair<int, int>>> vals;
for (int i = 0; i < P.size(); i++) {
vals.push_back({ i, { P[i], T[i] } });
}
sort(vals.begin(), vals.end(), comp);
vector<pair<int, int>> aa(P.size() + 1, { -1, -1 });
vector<vector<int>> p(P.size(), vector<int>(P.size(), -1));
aa[0] = { A, -1 };
for (int i = 0; i < P.size(); i++) {
for (int j = P.size() - 1; j >= 0; j--) {
if (aa[j].first < vals[i].second.first) continue;
if (aa[j + 1].first < (aa[j].first - vals[i].second.first) * vals[i].second.second) {
aa[j + 1] = { (aa[j].first - vals[i].second.first) * vals[i].second.second, i};
p[j][i] = aa[j].second;
}
}
}
int maxC = 0;
for (maxC = P.size(); maxC >= 0; maxC--) {
if (aa[maxC].first >= 0) break;
}
vector<int> res(maxC, -1);
int crnt = aa[maxC].second;
int cnt = 0;
while (crnt != -1) {
maxC--;
res[cnt++] = crnt;
crnt = p[maxC][crnt];
}
reverse(res.begin(), res.end());
for (int i = 0; i < res.size(); i++) res[i] = vals[res[i]].first;
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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |