제출 #346271

#제출 시각아이디문제언어결과실행 시간메모리
346271dennisstar카니발 티켓 (IOI20_tickets)C++17
27 / 100
670 ms51392 KiB
#include <bits/stdc++.h>
#include "tickets.h"
using namespace std;
using ll = long long;

ll find_maximum(int K, vector<vector<int>> X) {
	int N = X.size(), M=X[0].size();

	ll R=0;
	vector<int> T(N), L(N);
	priority_queue<pair<int, int>> pq;
	for (int i=0; i<N; i++) {
		pq.emplace(X[i][M-1]+X[i][K-1], i);
		for (int j=0; j<K; j++) R-=X[i][j];
	}

	for (int i=0; i<K*N/2; i++) {
		int j=pq.top().second;
		R+=pq.top().first;
		pq.pop();
		T[j]++;
		if (T[j]<K)
			pq.emplace(X[j][M-1-T[j]]+X[j][K-1-T[j]], i);
	}
	
	vector<vector<int>> A;
	while (pq.size()) pq.pop();
	for (int i=0; i<N; i++)
		A.emplace_back(vector<int>(M, -1)),
		pq.emplace(T[i], i);

	int mx=0, mn=(1e9);
	for (int i=0; i<N; i++) {
		if (T[i]<K) mx=max(mx, X[i][K-T[i]-1]);
		if (T[i]) mn=min(mn, X[i][M-T[i]]);
	}
	assert(mx<=mn);
	for (int i=0; i<K; i++) {
		vector<int> S;
		for (int j=0; j<N/2; j++) S.emplace_back(pq.top().second), pq.pop();
		sort(S.begin(), S.end());
		for (int j=0, k=0; j<N; j++) {
			if (k<N/2&&j==S[k]) {
				L[j]++;
				A[j][M-1-T[j]+L[j]]=i;
				if (L[j]<T[j])
					pq.emplace(T[j]-L[j], j);
				k++;
			}
			else A[j][i-L[j]]=i;
		}
	}

	allocate_tickets(A);
	return R;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...