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 <vector>
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
long long find_maximum(int k, vector<vector<int>> x) {
int n = x.size(), m = x[0].size();
long long S = 0;
vector<vector<int>> answer(n, vector<int>(m, -1));
vector<int> l(n, -1), r(n, m);
priority_queue<pair<ll, int>> pq;
for (int i = 0; i < n; i++) {
for (int j = 0; j < k; j++) {
S -= x[i][++l[i]];
pq.push({x[i][j] + x[i][m - k + j], i});
}
}
for (int iter = 0; iter < (n / 2) * k; iter++) {
int i = pq.top().second;
pq.pop();
S += x[i][--r[i]];
S += x[i][l[i]--];
}
for (int iter = 0; iter < k; iter++) {
int cnt = 0;
for (int i = 0; i < n; i++) {
if (r[i] == m) {
answer[i][l[i]--] = iter;
cnt++;
}
}
assert(cnt <= n / 2);
for (int i = 0; i < n; i++) {
if (r[i] == m) continue;
if (cnt < n / 2 && l[i] >= 0) {
answer[i][l[i]--] = iter;
cnt++;
} else {
answer[i][r[i]++] = iter;
}
}
}
allocate_tickets(answer);
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... |