이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "tickets.h"
#include <bits/stdc++.h>
using namespace std;
long long calc (vector<long long> &a) {
int n = a.size();
long long sum = accumulate(a.begin(), a.end(), 0LL), m = LLONG_MAX, sum2 = 0;
sort(a.begin(), a.end());
for (int i = 0; i < n; ++i) {
sum -= a[i];
m = min(m, a[i] * i - sum2 + sum - a[i] * (n - i - 1));
sum2 += a[i];
}
return m;
}
long long find_maximum(int k, vector<vector<int>> a) {
int n = a.size();
int m = a[0].size();
long long ans = 0;
vector<vector<int>> g(n, vector<int>(m, -1));
for (int kc = 0; kc < k; ++kc) {
vector<vector<array<int, 2>>> a2(n);
long long mxs = 0;
vector<long long> ask;
vector<array<int, 2>> ms;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (~a[i][j]) {
a2[i].push_back({a[i][j], j});
}
}
sort(a2[i].begin(), a2[i].end());
mxs += a2[i].back()[0];
ms.push_back({-a2[i][0][0] - a2[i].back()[0], i});
}
sort(ms.rbegin(), ms.rend());
for (int i = 0; i < n / 2; ++i) {
ask.push_back(a2[ms[i][1]][0][0]);
g[ms[i][1]][a2[ms[i][1]][0][1]] = kc;
a[ms[i][1]][a2[ms[i][1]][0][1]] = -1;
}
for (int i = n / 2; i < n; ++i) {
ask.push_back(a2[ms[i][1]].back()[0]);
g[ms[i][1]][a2[ms[i][1]].back()[1]] = kc;
a[ms[i][1]][a2[ms[i][1]].back()[1]] = -1;
}
ans += calc(ask);
}
allocate_tickets(g);
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... |