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 <bits/stdc++.h>
#define ar array
#define ll long long
#define all(x) x.begin(), x.end()
#include "tickets.h"
using namespace std;
const ll INF = 1e18;
long long find_maximum(int k, std::vector<std::vector<int>> a) {
int n = a.size();
int m = a[0].size();
ll ans2 = 0;
for (int i = 0; i < n; i++) for (int j = 0; j < k; j++) ans2 -= a[i][j];
vector<int> at(n, k - 1);
priority_queue<ar<ll, 2>> q;
for (int i = 0; i < n; i++) q.push({a[i][k-1] + a[i][m-1], i});
for (int t = 0; t < n / 2 * k; t++) {
auto [val, idx] = q.top(); q.pop();
ans2 += val;
assert(at[idx] >= 0);
if (--at[idx] >= 0) {
q.push({a[idx][at[idx]] + a[idx][m - (k - at[idx])], idx});
}
}
vector<vector<int>> ans(n, vector<int>(m, -1));
for (int i = 0, u = 0; i < n; i++) {
for (int j = 0; j <= at[i]; j++) {
ans[i][j] = u;
u = (u + 1) % k;
}
}
for (int i = 0; i < n; i++) {
int g = k - at[i] - 1;
vector<bool> used(k);
for (int j = 0; j <= at[i]; j++) used[ans[i][j]] = 1;
int on = 0;
for (int j = m - g; j < m; j++) {
while (on < k && used[on]) on++;
assert(on < k);
ans[i][j] = on++;
}
}
allocate_tickets(ans);
return ans2;
}
# | 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... |