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;
#define int long long
void allocate_tickets(vector<vector<signed>> s);
int find_maximum(signed k, vector<vector<signed>> x) {
int n = x.size(); int m = x[0].size();
vector<vector<signed>> s(n, vector<signed>(m,-1));
vector<stack<int>> pls(n);
vector<stack<int>> mns(n);
int ans = 0;
for (int i=0; i<n; i++) {
for (int j=0; j<k; j++) {
mns[i].push(j);
}
}
set<pair<int,int>> ps;
for (int i=0; i<n; i++) {
ps.insert({x[i][m - (k-mns[i].top())] + x[i][mns[i].top()],i});
}
for (int ct=0; ct<k*n/2; ct++) {
int i = (*ps.rbegin()).second; ps.erase(*ps.rbegin());
pls[i].push(m - (k-mns[i].top())); mns[i].pop();
if (mns[i].empty()) continue;
ps.insert({x[i][m - (k-mns[i].top())] + x[i][mns[i].top()],i});
}
set<pair<int,int>> pl;
for (int i=0; i<n; i++) pl.insert({pls[i].size(), i});
vector<int> bg(n, 0);
for (int rnd = 0; rnd<k; rnd++){
bg.assign(n,0);
for (int i=0; i<n/2; i++) {
bg[(*pl.rbegin()).second] = 1; pl.erase(*pl.rbegin());
}
for (int i=0; i<n; i++) {
if (bg[i]) {
ans += x[i][pls[i].top()];
s[i][pls[i].top()]=rnd; pls[i].pop();
pl.insert({pls[i].size(), i});
} else {
ans -= x[i][mns[i].top()];
s[i][mns[i].top()]=rnd; mns[i].pop();
}
}
}
allocate_tickets(s);
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... |