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"
using namespace std;
typedef long long ll;
struct dat{
int i, l, r; ll val;
dat(){}
dat(int i, int l, int r, ll val): i(i), l(l), r(r), val(val){}
bool operator<(const dat &tr)const{
if(val == tr.val) return l < tr.l;
return val < tr.val;
}
};
vector<vector<int> > ans;
ll ansV;
vector<dat> vec;
queue<int> small[1502], big[1502];
int only[1502]; /// 0: all, 1: only small, 2: only big
ll find_maximum(int k, vector<vector<int>> x) {
int n = x.size(), nh = n/2;
int m = x[0].size();
ans.resize(n);
for(int i=0; i<n; i++) ans[i] = vector<int>(m, -1);
for(int i=0; i<n; i++){
for(int j=0; j<k; j++){
ansV += x[i][m-k+j];
vec.push_back(dat(i, j, m-k+j, x[i][j] + x[i][m-k+j]));
big[i].push(m-k+j);
}
}
sort(vec.begin(), vec.end());
for(int i=0; i<nh*k; i++){
dat tmp = vec[i];
ansV -= tmp.val;
assert(big[tmp.i].front() == tmp.r);
big[tmp.i].pop();
small[tmp.i].push(tmp.l);
}
for(int c=0; c<k; c++){
for(int i=0; i<n; i++){
if(big[i].empty()) only[i] = 1;
else if(small[i].empty()) only[i] = 2;
else only[i] = 0;
}
int smallCnt = 0, bigCnt = 0;
for(int i=0; i<n; i++){
if(!only[i]) continue;
if(only[i] == 1){
ans[i][small[i].front()] = c;
small[i].pop(), smallCnt++;
}
else{
ans[i][big[i].front()] = c;
big[i].pop(), bigCnt++;
}
}
for(int i=0; i<n; i++){
if(only[i]) continue;
if(smallCnt < nh){
ans[i][small[i].front()] = c;
small[i].pop(), smallCnt++;
}
else{
ans[i][big[i].front()] = c;
big[i].pop(), bigCnt++;
}
}
}
allocate_tickets(ans);
return ansV;
}
# | 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... |