#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define _ << " " <<
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define ull unsigned long long
#define lll __int128
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define BlueCrowner ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
const ll mod = 1e9 + 7;
const ll mod1 = 998244353;
const ll naim = 1e9;
const ll max_bit = 60;
const ull tom = ULLONG_MAX;
const ll MAXN = 100005;
const ll LOG = 20;
const ll NAIM = 1e18;
const ll N = 2e6 + 5;
std::vector<int> max_coupons(int A, std::vector<int> P, std::vector<int> T) {
ll n = P.size();
vector<ll> p(all(P)), t(all(T));
vector<int> res;
vector<int> ord(n);
iota(all(ord), 0);
sort(all(ord), [&](ll i, ll j){
if(t[i] == t[j]) return p[i] < p[j];
return p[i] * t[i] * t[j] + p[j] * t[j] < p[j] * t[j] * t[i] + p[i] * t[i];
});
vector<vector<pair<ll, ll>>> c(5);
ll cur = A;
FOR(i, 0, n) {
ll pos = ord[i];
if((cur - p[pos]) * t[pos] >= cur) {
res.pb(pos);
cur = (cur - p[pos]) * t[pos];
if(cur > NAIM) {
return ord;
}
}
else {
c[t[pos]].pb({p[pos], pos});
}
}
vector<vector<vector<ll>>> dp(35, vector<vector<ll>>(35, vector<ll>(35, -1)));
FOR(i, 2, 5) if(c[i].size() >= 35) c[i].resize(34);
dp[0][0][0] = cur;
FOR(i, 0, c[2].size() + 1) FOR(j, 0, c[3].size() + 1) FOR(k, 0, c[4].size() + 1) {
if(i) dp[i][j][k] = max(dp[i][j][k], (dp[i - 1][j][k] - c[2][i - 1].ff) * 2);
if(j) dp[i][j][k] = max(dp[i][j][k], (dp[i][j - 1][k] - c[3][j - 1].ff) * 3);
if(k) dp[i][j][k] = max(dp[i][j][k], (dp[i][j][k - 1] - c[4][k - 1].ff) * 4);
}
vector<ll> pref(c[1].size() + 1, 0);
FOR(i, 1, c[1].size() + 1) pref[i] = pref[i - 1] + c[1][i - 1].ff;
ll mx = 0;
vector<ll> num = {0, 0, 0, 0};
FOR(i, 0, 35) FOR(j, 0, 35) FOR(k, 0, 35) {
if(dp[i][j][k] < 0) continue;
ll pos = upper_bound(all(pref), dp[i][j][k]) - pref.begin();
if(i + j + k + pos - 1 > mx) {
mx = i + j + k + pos - 1;
num = {i, j, k, pos - 1};
}
}
vector<ll> res1;
while(num[0] + num[1] + num[2]) {
ll &i = num[0], &j = num[1], &k = num[2];
if(i && (dp[i - 1][j][k] - c[2][i - 1].ff) * 2 == dp[i][j][k]){
res1.pb(c[2][i - 1].ss);
i--;
}
else if(j && (dp[i][j - 1][k] - c[3][j - 1].ff) * 3 == dp[i][j][k]) {
res1.pb(c[3][j - 1].ss);
j--;
}
else {
res1.pb(c[4][k - 1].ss);
k--;
}
}
reverse(all(res1));
for(auto &x : res1) res.pb(x);
FOR(i, 1, num[3] + 1) res.pb(c[1][i - 1].ss);
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... |