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;
pair<int,int> a[2000][2000];
int cnt[2000], vis[2000], cnt2[2000];
ll find_maximum(int k, vector<vector<int>> x) {
int n = x.size(), m = x[0].size();
vector<vector<int>> y(n, vector<int>(m, -1));
priority_queue<array<int,2>> pq;
ll ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++)
a[i][j] = make_pair(x[i][j], j);
sort(a[i], a[i]+m);
for (int j1 = k-1, j2 = m-1; ~j1; j1--, j2--)
pq.push({a[i][j1].first + a[i][j2].first, i}), ans -= a[i][j1].first;
}
for (int i = 0; i < k * n / 2; i++, pq.pop())
ans += pq.top()[0], cnt[pq.top()[1]]++;
while (!pq.empty()) pq.pop();
for (int i = 0; i < n; i++)
pq.push({cnt[i], i});
for (int i = 0; i < k; i++) {
for (int j = 0; j < n / 2; j++, pq.pop())
vis[pq.top()[1]] = 1;
for (int j = 0; j < n; j++)
if (vis[j])
vis[j] = 0, y[j][a[j][m-cnt[j]].second] = i, pq.push({--cnt[j], j});
else
y[j][a[j][cnt2[j]++].second] = i;
}
allocate_tickets(y);
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... |