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 iii = tuple<int, int, int>;
ll find_maximum(int k, vector<vector<int> > x) {
int n = x.size(), m = x[0].size();
vector<vector<int> > out(n, vector<int>(m, 0)), add(n), sub(n);
ll ret = 0;
vector<iii> vals;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
vals.eb(x[i][j], i, j);
}
}
sort(vals.begin(), vals.end());
for (int i = 0; i < n * m; i++) {
auto [_, x, y] = vals[i];
if (i < n * m / 2) {
sub[x].pb(y);
} else {
add[x].pb(y);
}
}
for (int i = 0; i < m; 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... |