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;
#define pb push_back
#define eb emplace_back
using ll = long long;
using ii = pair<int, int>;
using iii = tuple<int, int, int>;
ll find_maximum(int k, vector<vector<int> > x) {
int n = x.size(), m = x[0].size();
ll ret = 0;
vector<int> num_sub(n, 0);
vector<vector<int> > out(n, vector<int>(m, -1)), add(n), sub(n);
priority_queue<iii> pq;
for (int i = 0; i < n; i++) {
pq.emplace(-x[i][m - k] - x[i][0], i, 0);
}
for (int j = 0; j < n * k / 2; j++) {
auto [_, i, sft] = pq.top();
pq.pop();
num_sub[i]++;
if (sft < k) {
pq.emplace(-x[i][m - k + sft + 1] - x[i][sft + 1], i, sft + 1);
}
}
for (int i = 0; i < n; i++) {
vector<ii> cur;
for (int j = 0; j < m; j++) {
cur.eb(x[i][j], j);
}
sort(cur.begin(), cur.end());
for (int j = 0; j < num_sub[i]; j++) {
sub[i].pb(cur[j].second);
}
for (int j = m - (k - num_sub[i]); j < m; j++) {
add[i].pb(cur[j].second);
}
}
for (int i = 0; i < k; i++) {
vector<int> ord;
for (int j = 0; j < n; j++) {
ord.pb(j);
}
sort(ord.begin(), ord.end(), [&](const auto &lhs, const auto &rhs) {
return sub[lhs].size() < sub[rhs].size();
});
vector<int> cur;
for (int j = 0; j < n / 2; j++) {
cur.pb(x[ord[j]][add[ord[j]].back()]);
out[ord[j]][add[ord[j]].back()] = i;
add[ord[j]].pop_back();
}
for (int j = n / 2; j < n; j++) {
cur.pb(x[ord[j]][sub[ord[j]].back()]);
out[ord[j]][sub[ord[j]].back()] = i;
sub[ord[j]].pop_back();
}
sort(cur.begin(), cur.end());
for (auto j : cur) {
ret += llabs(j - cur[cur.size() / 2]);
}
}
allocate_tickets(out);
return ret;
}
# | 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... |