This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#ifdef imeimi
#include <vector>
long long find_maximum(int k, std::vector<std::vector<int>> d);
void allocate_tickets( std::vector<std::vector<int>> _x);
#include <cassert>
#include <cstdio>
#include <vector>
#include <string>
static int n;
static int m;
static int k;
static std::vector<std::vector<int>> d;
static std::vector<std::vector<int>> x;
static int called = 0;
static void check(bool cond, std::string message) {
if (!cond) {
printf("%s\n", message.c_str());
exit(0);
}
}
void allocate_tickets( std::vector<std::vector<int>> _d) {
check(!called, "allocate_tickets called more than once");
d = _d;
check((int)d.size() == n, "allocate_tickets called with parameter of wrong size");
for (int i = 0; i < n; i++) {
check((int)d[i].size() == m, "allocate_tickets called with parameter of wrong size");
}
called = 1;
}
int main() {
assert(scanf("%d %d %d", &n, &m, &k) == 3);
x.resize(n);
for (int i = 0; i < n; i++) {
x[i].resize(m);
for (int j=0; j < m; j++) {
assert(scanf("%d", &x[i][j]) == 1);
}
}
fclose(stdin);
long long answer = find_maximum(k, x);
check(called, "failure to call allocate_tickets");
printf("%lld\n", answer);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (j) printf(" ");
printf("%d", d[i][j]);
}
printf("\n");
}
fclose(stdout);
return 0;
}
#else
#include "tickets.h"
#endif
#include <bits/stdc++.h>
using namespace std;
typedef long long llong;
typedef pair<int, int> pii;
llong find_maximum(int k, vector<vector<int>> X) {
int n = X.size(), m = X[0].size();
llong ret = 0;
vector<pii> ord;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < k; ++j) ret -= X[i][j];
for (int j = 0; j < k; ++j) {
ord.emplace_back(X[i][j] + X[i][j + m - k], i);
}
}
sort(ord.rbegin(), ord.rend());
while (int(ord.size()) > n * k / 2) ord.pop_back();
vector<int> pcnt(n, 0);
for (auto [c, i] : ord) {
ret += c;
++pcnt[i];
}
priority_queue<pii> pq;
for (int i = 0; i < n; ++i) pq.emplace(pcnt[i], i);
vector<vector<int>> ans(n, vector<int>(m, -1));
vector<int> lcnt(n, 0), hcnt = pcnt;
for (int r = 0; r < k; ++r) {
vector<bool> used(n, 0);
for (int i = 0; i < n / 2; ++i) {
int j = pq.top().second; pq.pop();
used[j] = 1;
ans[j][m - (hcnt[j]--)] = r;
}
for (int i = 0; i < n; ++i) {
if (used[i]) pq.emplace(hcnt[i], i);
else ans[i][lcnt[i]++] = r;
}
}
allocate_tickets(ans);
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... |