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;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
long long find_maximum(int K, std::vector<std::vector<int>> x)
{
int N = x.size();
int M = x[0].size();
ll value = 0;
vvi ans(N, vi(M, -1));
vpii A;
for (int i = 0; i < N; ++i)
for (int j = 0; j < M; ++j)
A.push_back({x[i][j], i * M + j});
sort(all(A));
for (int i = 0; i < N * M / 2; ++i)
value -= A[i].first;
for (int i = N * M / 2; i < N * M; ++i)
value += A[i].first;
A.resize(N * M / 2);
sort(all(A), [&](const pii &a, const pii &b)
{ return a.second / M < b.second / M; });
int k = 0;
for (pii tmp : A)
ans[tmp.second / M][tmp.second % M] = (k++ % M);
for (int i = 0; i < N; ++i)
{
vi V;
for (int j = 0; j < M; ++j)
if (ans[i][j] != -1)
V.push_back(ans[i][j]);
sort(all(V));
reverse(all(V));
k = 0;
for (int j = 0; j < M; ++j)
{
while (!V.empty() && k == V.back())
k++, V.pop_back();
if (ans[i][j] == -1)
ans[i][j] = k++;
}
}
allocate_tickets(ans);
return value;
}
# | 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... |