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"
#define ll long long
using namespace std;
const int N = 2e3 + 10;
ll find_maximum(int k, vector < vector < int > > x) {
priority_queue < pair < int, int > > pq;
vector < pair < int, int > > p(N);
stack < int > st[N];
stack < int > a[N];
int n = x.size();
int m = x[0].size();
ll res = 0;
for(int i = 0; i < n; i++) {
p[i].second = i;
for(int j = m - 1; j >= m - k; j--) {
st[i].push(x[i][j]);
res += st[i].top();
}
for(int j = m - 1; j >= 0; j--) a[i].push(x[i][j]);
if(st[i].size() && a[i].size()) pq.push({- a[i].top() - st[i].top(), i});
}
vector < vector < int > > l(n, vector < int >());
vector < vector < int > > r(n, vector < int >());
for(int i = 0; i < n * k / 2; i++) {
int f = pq.top().first;
int s = pq.top().second;
pq.pop();
res += f;
p[s].first++;
st[s].pop();
a[s].pop();
if(st[s].size() && a[s].size()) pq.push({- a[s].top() - st[s].top(), s});
}
vector < vector < int > > vr(n, vector < int > (m, -1));
for(int i = 0; i < n; i++) {
for(int j = 0; j < p[i].first; j++) l[i].push_back(j);
for(int j = m - (k - p[i].first); j < m; j++) r[i].push_back(j);
}
for(int i = 0; i < k; i++) {
sort(p.rbegin(), p.rend());
for(int j = 0; j < n / 2; j++) {
vr[p[j].second][l[p[j].second].back()] = i;
p[j].first--;
l[p[j].second].pop_back();
}
for(int j = n / 2; j < n; j++) {
vr[p[j].second][r[p[j].second].back()] = i;
r[p[j].second].pop_back();
}
}
allocate_tickets(vr);
return res;
}
# | 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... |