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 "tickets.h"
#include <bits/stdc++.h>
using namespace std;
long long find_maximum(int k, vector<vector<int>> a) {
int n = (int)a.size(), m = (int)a[0].size();
long long res = 0;
vector<vector<int>> bad(n, vector<int>(m));
for (int i = 0; i < n; i++) {
for (int j = 0; j < k; j++) {
res -= a[i][j];
}
}
priority_queue<array<int, 3>> pq;
for (int i = 0; i < n; i++) {
pq.push({a[i][m - 1] + a[i][k - 1], i, 0});
}
vector<int> cnt(n, k);
for (int i = 0; i < n * k / 2; i++) {
auto [x, j, d] = pq.top();
pq.pop();
res += x;
cnt[j] -= 1;
if (d + 1 < k - 1) pq.push({a[j][m - 1 - (d + 1)] + a[j][k - 1 - (d + 1)], j, d + 1});
}
vector<int> pl(n, 0), pr(n, m - 1);
vector<vector<int>> ans(n, vector<int>(m, -1));
for (int i = 0; i < k; i++) {
vector<int> ord(n);
iota(ord.begin(), ord.end(), 0);
sort(ord.begin(), ord.end(), [&](int x, int y) {
return cnt[x] > cnt[y];
});
for (int j = 0; j < n / 2; j++) {
ans[ord[j]][pl[ord[j]]++] = i;
cnt[ord[j]] -= 1;
}
for (int j = 0; j < n / 2; j++) {
ans[ord[j]][pr[ord[j]]--] = i;
}
}
allocate_tickets(ans);
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... |