Submission #1360295

#TimeUsernameProblemLanguageResultExecution timeMemory
1360295cowkimCarnival Tickets (IOI20_tickets)C++20
0 / 100
0 ms344 KiB
#include "tickets.h"
#include <bits/stdc++.h>
using namespace std;

long long find_maximum(int k, std::vector<std::vector<int>> x) {
	int n = x.size();
	int m = x[0].size();
	vector<int> l(n,0);
	vector<int> r(n,m-k);
	priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
	for(int i = 0; i< n; i++){
		pq.push({r[i] + l[i],i});
	}
	int nrunder = k*n/2;
	for(int i = 0; i< nrunder; i++){
		int curi = pq.top().second;
		pq.pop();
		l[curi]++;
		r[curi]++;
		if(r[curi] == m) continue;
		pq.push({r[curi] + l[curi],curi});
	}
	long long totprize = 0;
	for(int i = 0; i< n; i++){
		for(int j = 0; j< l[i]; j++){
			totprize -= x[i][j];
		}
		for(int j = r[i]; j < m; j++){
			totprize += x[i][j];
		}
	}
	vector<vector<int>> ans(n,vector<int>(m,-1));
	int half = n/2;
	int forcedl = 0;
	int forcedr = 0;
	for(int i = 0; i< n; i++){
		if(l[i] == 0) forcedr++;
		else if(r[i] == m) forcedl++;
	}
	for(int round = 0; round < k; round++){
		int curl = forcedl;
		int curr = forcedr;
		for(int i = 0; i< n; i++){
			if(l[i] == 0) ans[i][r[i]++] = round;
			else if(r[i] == m) ans[i][l[i]--] = round;
			else if(curl < half){
				ans[i][l[i]--] = round;
				curl++;
				if(l[i] == 0) forcedr++;
			}
			else{
				ans[i][r[i]++] = round;
				curr++;
				if(r[i] == m) forcedl++;
			}
		}
	}
	allocate_tickets(ans);
	return totprize;
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...