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>> x) {
int n = x.size(), m = x[0].size();
long long res = 0;
vector<array<int, 3>> cands;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < k; ++j) {
cands.push_back({x[i][j] + x[i][m - k + j], i, -j});
res -= x[i][j];
}
}
sort(cands.rbegin(), cands.rend());
vector<int> cnt(n), ptr(n);
for (int i = 0; i < n * k / 2; ++i) {
auto [v, r, c] = cands[i];
++cnt[r];
res += v;
}
vector a(n, vector<int>(m, -1));
vector<int> ord(n); iota(ord.begin(), ord.end(), 0);
for (int t = 0; t < k; ++t) {
sort(ord.begin(), ord.end(), [&](int u, int v) {
return cnt[u] > cnt[v];
});
for (int i = 0; i < n / 2; ++i) {
int u = ord[i];
a[u][m - cnt[u]--] = t;
}
for (int i = n / 2; i < n; ++i) {
int u = ord[i];
a[u][ptr[u]++] = t;
}
}
allocate_tickets(a);
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... |