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/extc++.h"
using namespace std;
template <typename T>
void dbgh(const T& t) {
cerr << t << endl;
}
template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
cerr << t << " | ";
dbgh(u...);
}
#ifdef DEBUG
#define dbg(...) \
cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]: "; \
dbgh(__VA_ARGS__);
#else
#define dbg(...)
#define cerr \
if (false) \
cerr
#endif
using ll = long long;
#define endl "\n"
#define long int64_t
#define sz(x) int((x).size())
void allocate_tickets(std::vector<std::vector<int>> _x);
ll find_maximum(int k, vector<vector<int>> arr) {
int n = sz(arr), m = sz(arr[0]);
long ans = 0;
for (auto& a : arr) {
assert(is_sorted(begin(a), end(a)));
ans -= accumulate(a.begin(), a.begin() + k, long(0));
}
int cnt[n] {};
priority_queue<pair<int, int>> pq;
auto upd = [&](int i) -> void {
if (cnt[i] >= k) {
return;
}
pq.emplace(arr[i][k - cnt[i] - 1] + arr[i][m - cnt[i] - 1], i);
};
for (int i = 0; i < n; i++) {
upd(i);
}
for (int i = 0; i < n * k / 2; i++) {
auto [d, j] = pq.top();
pq.pop();
ans += d;
cnt[j]++;
upd(j);
}
vector<vector<int>> qans(n, vector<int>(m, -1));
vector<int> inds[n][2];
for (int i = 0; i < n; i++) {
for (int j = 0; j < k - cnt[i]; j++) {
inds[i][0].push_back(j);
}
for (int j = 0; j < cnt[i]; j++) {
inds[i][1].push_back(m - j - 1);
}
}
for (int i = 0; i < k; i++) {
int cur = 0;
for (int j = 0; j < n; j++) {
int ci;
if (cur < n / 2 && sz(inds[j][0])) {
cur++;
ci = 0;
} else {
ci = 1;
}
qans[j][inds[j][ci].back()] = i;
inds[j][ci].pop_back();
}
}
allocate_tickets(qans);
return ans;
}
# | 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... |