제출 #346282

#제출 시각아이디문제언어결과실행 시간메모리
346282dennisstarCarnival Tickets (IOI20_tickets)C++17
27 / 100
653 ms51564 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();

	vector<int> T(N), l(N), r(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 i=0; i<K*N/2; i++) {
		int j=pq.top().second;
		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);

	ll R=0;
	for (int i=0; i<K; i++) {
		vector<int> chk(N);
		for (int j=0; j<N/2; j++) chk[pq.top().second]=1, pq.pop();
		for (int j=0; j<N; j++) {
			if (chk[j]) {
				l[j]++;
				A[j][M-l[j]]=i;
				R+=X[j][M-l[j]];
				pq.emplace(T[j]-l[j], j);
			}
			else A[j][r[j]]=i, R-=X[j][r[j]], r[j]++;
		}
	}

	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...