#include "tickets.h"
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const ll inf = 1e18;
long long find_maximum(int k, std::vector<std::vector<int>> a) {
int n = a.size();
int m = a[0].size();
vector<int> pos(n);
vector vec(n, vector(m, -1));
ll ans = 0;
for (int i = 0; i < n; i++) for (int j = m - k; j < m; j++) ans += a[i][j];
priority_queue<pair<ll, int>> pq;
for (int i = 0; i < n; i++) pq.emplace(-a[i][0] - a[i][m - k], i);
for (int shit = 0; shit < n * k / 2; shit++) {
auto [d, i] = pq.top(); pq.pop();
ans += d;
pos[i]++;
if (pos[i] < k) pq.emplace(-a[i][pos[i]] - a[i][m - (k - pos[i])], i);
}
vector<tuple<int, int, int>> right;
vector<vector<int>> left(n);
vector<int> taken(n);
vector<pair<int, int>> have(n);
for (int i = 0; i < n; i++) {
vector<int> v;
for (int j = 0; j < pos[i]; j++) v.emplace_back(a[i][j]);
for (int j = m - (k - pos[i]); j < m; j++) right.emplace_back(a[i][j], i, j);
left[i] = v;
have[i] = make_pair(pos[i], i);
}
sort(right.begin(), right.end());
for (int shit = 0; shit < k; shit++) {
sort(have.rbegin(), have.rend());
vector<bool> used(n);
vector<int> v;
int cnt = 0;
for (int i = 0; i < n / 2; i++) {
used[have[i].second] = true;
have[i].first--;
v.emplace_back(a[have[i].second][taken[have[i].second]]);
vec[have[i].second][taken[have[i].second]++] = shit;
}
vector<tuple<int, int, int>> nw;
cnt = 0;
for (auto [x, i, j]: right) {
if (used[i] or cnt == n / 2 or v[cnt] > x) {
nw.emplace_back(x, i, j);
continue;
}
vec[i][j] = shit;
used[i] = true;
cnt++;
}
right = nw; nw.clear();
assert(cnt == n / 2);
}
allocate_tickets(vec);
return ans;
}
# | 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... |