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 "tickets.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define F first
#define S second
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define pb push_back
#define eb emplace_back
#define SZ(a) ((int)a.size())
#define REP(i,n) for(int i=0;i<(n);i++)
const int maxn = 1505;
int n,m,k;
vector<vector<ll>> a;
std::vector<std::vector<int>> ans;
vector<int> idx[maxn]; //pos
vector<int> idx2[maxn]; //neg
void distribute(){//distrubute all tickets in idx[] to k rounds, each round with n/2 distinct color
set<pii> st;
REP(i,n){
st.insert(MP(SZ(idx[i]),i));
}
REP(i,k){
auto it = prev(st.end());
vector<int> clr={};
bool vis[maxn]={0};
REP(j,n/2){
clr.pb(it->S);
--it;
}
for(int j:clr){
vis[j] = 1;
ans[j][idx[j].back()] = i;
st.erase(MP(SZ(idx[j]),j));
idx[j].pop_back();
st.insert(MP(SZ(idx[j]),j));
}
REP(j,n) if(!vis[j]){
ans[j][idx2[j].back()] = i;
idx2[j].pop_back();
}
}
}
// bool check(vector<int> v){
// assert(SZ(v)==n);
// sort(ALL(v));
// reverse(ALL(v));
// int sum = 0;
// REP(i,SZ(v)){
// sum+=v[i];
// if(sum>(i+1) * k) return 0;
// }
// return 1;
// }
ll val[maxn][maxn];
priority_queue<pll> pq;
int iter[maxn];
long long find_maximum(int _k, std::vector<std::vector<int>> x) {
n = x.size();
m = x[0].size();
k=_k;
a.resize(n);
REP(i,n) REP(j,m) a[i].pb(x[i][j]);
ans.resize(n);
REP(i,n) ans[i].resize(m);
REP(i,n) REP(j,m) ans[i][j]=-1;
ll ret = 0;
REP(i,n){
vector<ll> tmp = a[i];
sort(ALL(tmp));
REP(j,k) ret -= tmp[j];
REP(j,k){
val[i][j] = tmp[SZ(tmp)-1-j] + tmp[k-1-j];
}
}
REP(i,n) iter[i] = 0;
REP(i,n) pq.push(MP(val[i][0],i));
REP(T,n*k/2){
auto cur = pq.top();
pq.pop();
int idx = cur.S;
ret += cur.F;
iter[idx]++;
pq.push(MP(val[idx][iter[idx]],idx));
}
// REP(i,n) cout<<iter[i]<<" \n"[i==n-1];
{
REP(i,n){
vector<pll> _;
REP(j,m) _.eb(a[i][j],j);
sort(ALL(_));
REP(j,k-iter[i]){
idx2[i].pb(_[j].S);
}
reverse(ALL(_));
REP(j,iter[i]){
idx[i].pb(_[j].S);
}
}
// REP(i,n) {
// for(int j:idx[i]) cout<<j<<' ';
// cout<<'\n';
// }
distribute();
}
allocate_tickets(ans);
return ret;
}
# | 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... |