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;
void allocate_tickets(vector<vector<int> > s);
long long find_maximum(int k, vector<vector<int> > x){
int n = x.size(), m = x[0].size();
vector<vector<int> > s(n);
vector<int> num(n), l(n), r(n);
for(int i=0;i<n;i++){
s[i].resize(m);
r[i] = m-1;
for(int j=0;j<m;j++) s[i][j] = -1;
}
long long ans = 0;
priority_queue<pair<int, int> > pq;
for(int i=0;i<n;i++){
for(int j=k-1;j>=0;j--){
pq.push(make_pair(x[i][j]+x[i][m-1-(k-1-j)], i));
ans += -x[i][j];
}
}
for(int i=0;i<n*k/2;i++){
int val = pq.top().first, j = pq.top().second;
pq.pop();
ans += val;
num[j]++;
}
for(int i=0;i<k;i++){
vector<pair<int, int> > v;
for(int j=0;j<n;j++) v.push_back(make_pair(num[j], j));
sort(v.begin(), v.end());
reverse(v.begin(), v.end());
for(int j=0;j<n/2;j++){
int idx = v[j].second;
s[idx][r[idx]--] = i;
num[idx]--;
}
for(int j=n/2;j<n;j++){
int idx = v[j].second;
s[idx][l[idx]++] = i;
}
}
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... |