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;
using ll = long long;
ll find_maximum(int k, vector<vector<int>> x) {
int n = x.size();
int m = x[0].size();
assert(n % 2 == 0);
vector<vector<int>> xs = x;
vector<pair<int,int>> stones(n*k);
ll s = 0;
for (int i = 0; i < n; i++) {
sort(xs[i].begin(), xs[i].end());
for (int j = 0; j < k; j++) {
s -= xs[i][j];
stones.emplace_back(xs[i][m-j-1] + xs[i][k-j-1], i);
}
}
vector<int> ts(n);
sort(stones.begin(), stones.end());
for (int it = 0; it < k*n/2; it++) {
auto [v, i] = stones.back(); stones.pop_back();
s += v;
ts[i]++;
}
vector<vector<int>::iterator> bads(n), guds(n);
for (int i = 0; i < n; i++) {
bads[i] = xs[i].begin();
guds[i] = xs[i].begin() + m - ts[i];
}
vector<vector<int>> roundv(n, vector<int>(k, -1));
vector<int> rows(n);
iota(rows.begin(), rows.end(), 0);
for (int r = 0; r < k; r++) {
sort(rows.begin(), rows.end(), [&](int i, int j) { return distance(guds[i], xs[i].end()) < distance(guds[j], xs[j].end()); });
for (int idx = 0; idx < n; idx++) {
int i = rows[idx];
roundv[i][r] = *((idx < n/2 ? bads : guds)[i]++);
}
}
vector<vector<int>> take(n, vector<int>(m, -1));
for (int i = 0; i < n; i++) {
assert(bads[i] == xs[i].begin() + k - ts[i]);
assert(guds[i] == xs[i].end());
unordered_map<int,vector<int>> inds;
for (int j = 0; j < m; j++) {
inds[x[i][j]].push_back(j);
}
for (int r = 0; r < k; r++) {
int v = roundv[i][r];
take[i][inds[v].back()] = r; inds[v].pop_back();
}
}
allocate_tickets(take);
return s;
}
# | 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... |