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>
using namespace std;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif
#ifdef tabr
void allocate_tickets(vector<vector<int>>) {}
#else
#include "tickets.h"
#endif
long long find_maximum(int k, vector<vector<int>> x) {
int n = (int) x.size();
int m = (int) x[0].size();
vector<pair<int, int>> a;
long long res = 0;
for (int i = 0; i < n; i++) {
res -= accumulate(x[i].begin(), x[i].begin() + k, 0LL);
for (int j = 0; j < k; j++) {
a.emplace_back(x[i][m - 1 - j] + x[i][k - 1 - j], i);
}
}
sort(a.rbegin(), a.rend());
vector<int> big(n), small(n, k);
for (int i = 0; i < n * k / 2; i++) {
res += a[i].first;
big[a[i].second]++;
small[a[i].second]--;
}
vector<vector<int>> s(n, vector<int>(m, -1));
for (int i = 0; i < k; i++) {
int small_cnt = 0;
int big_cnt = 0;
for (int j = 0; j < n; j++) {
if (big[j] == 0) {
small[j]--;
s[j][small[j]] = i;
small_cnt++;
} else if (small[j] == 0) {
big[j]--;
s[j][m - 1 - big[j]] = i;
big_cnt++;
}
}
for (int j = 0; j < n; j++) {
if (big[j] > 0 && small[j] > 0) {
if (small_cnt < n / 2) {
small[j]--;
s[j][small[j]] = i;
small_cnt++;
} else {
big[j]--;
s[j][m - 1 - big[j]] = i;
big_cnt++;
}
}
}
}
debug(s);
allocate_tickets(s);
return res;
}
#ifdef tabr
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
debug(find_maximum(2, {{0, 2, 5}, {1, 1, 3}})); // 7
debug(find_maximum(1, {{5, 9}, {1, 4}, {3, 6}, {2, 7}})); // 12
debug(find_maximum(2, {{1, 4, 5, 9}, {1, 2, 3, 4}, {3, 4, 5, 6}, {1, 2, 7, 8}}));
return 0;
}
#endif
# | 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... |