# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1124131 | epicci23 | 카니발 티켓 (IOI20_tickets) | C++17 | 0 ms | 0 KiB |
#include "tickets.h"
#include "bits/stdc++.h"
using namespace std;
long long find_maximum(int k, vector<vector<int>> x) {
long long n = x.size(),m = x[0].size(),tot = 0;
vector<vector<int>> ans(n,vector<int>(m,-1));
priority_queue<array<long long,2>> pq;
vector<long long> p(n,1);
for(int i=0;i<n;i++) pq.push({x[i][k-p[i]]+x[i][m-p[i]],i});
for(int i=0;i<k*n/2;i++){
array<long long,2> u = pq.top();
pq.pop();
tot += u[0];
long long ind = u[1];
p[ind]++;
pq.push({x[ind][k-p[ind]]+x[ind][m-p[ind]],ind});
}
vector<long long> lf(n);
for(int i=0;i<n;i++) lf[i]=p[i]-1;
array<long long,2> tag[n];
for(int i=0;i<n;i++) tag[i]={0,0};
for(int i=0;i<k;i++){
vector<array<long long,2>> v;
for(int j=0;j<n;j++) v.push_back({lf[j],j});
sort(v.begin(),v.end());
reverse(v.begin(),v.end());
vector<long long> vals;
for(int j=0;j<n;j++){
long long ind = v[j][1];
if(j<n/2){
lf[ind]--;
tag[ind][1]++;
ans[ind][m-tag[ind][1]]=i;
vals.push_back(x[ind][m-tag[ind][1]]);
}
else{
vals.push_back(x[ind][tag[ind][0]]);
ans[ind][tag[ind][0]]=i;
tag[ind][0]++;
}
}
sort(all(vals));
for(int j=0;j<n;j++){
if(j<n/2) tot -= vals[j];
else tot += vals[j];
}
}
allocate_tickets(ans);
return tot;
}