# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
928069 | EJIC_B_KEDAX | Carnival Tickets (IOI20_tickets) | C++17 | 0 ms | 0 KiB |
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>
#include "tickets.h"
using ll = long long;
using namespace std;
int64_t find_maximum(int k, vector<vector<int>> t) {
int n = t.size(), m = t[0].size();
vector<int> all;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
all.push_back(t[i][j]);
}
}
sort(all.begin(), all.end());
int middle = all[all.size() / 2];
ll res = 0;
vector<pair<ll, int>> a(n);
vector<int> bg(n, 0), end(n, m - 1);
vector<vector<int>> s(n, vector<int>(m, -1));
for (int i = 0; i < n; i++) {
a[i].first = 0;
a[i].second = i;
for (int j = 0; j < m; j++) {
t[i][j] -= middle;
res += abs(a[i][j]);
a[i].first += t[i][j];
}
}
for (int r = 0; r < k; r++) {
sort(a.begin(), a.end());
for (int i = 0; i < n / 2; i++) {
a[i].first -= t[a[i].second][bg[a[i].second]];
s[a[i].second][bg[a[i].second]++] = r;
}
for (int i = n / 2; i < n; i++) {
a[i].first -= t[a[i].second][end[a[i].second]];
s[a[i].second][end[a[i].second]--] = r;
}
}
allocate_tickets(s);
return res;
}