Submission #578254

#TimeUsernameProblemLanguageResultExecution timeMemory
578254VanillaCarnival Tickets (IOI20_tickets)C++17
27 / 100
484 ms51828 KiB
#include <bits/stdc++.h>
#include "tickets.h"
using namespace std;
 
struct el {
	long long x, y, idx;
 
	bool operator < (const el &oth) const {
		return y + x < oth.x + oth.y;
	}
};

struct val {
	long long v, x, y;

	bool operator < (const val &oth) const {
		return v < oth.v;
	}
};
 
// bool comp (pair <long, long> a, pair <long, long> b) {
// 	if (a.first != b.first) return a.first < 
// }
 
long long find_maximum(int k, vector<vector<int>> x) {
	long long n = x.size();
	long long m = x[0].size();
	long long rs = 0;
	vector <int> times (n, 1);
	vector <vector <int> > answer (n, vector <int> (m, -1));
	vector <vector <bool> > take (n, vector <bool> (m, 0));
	priority_queue <el> pq;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < k; j++){
			rs-=x[i][j];
			take[i][j] = 1;
		}
		pq.push({x[i][k-1], x[i][m-1], i});
	}
	for (int z = 0; z < n * k / 2; z++){
		el now = pq.top();
		pq.pop();
		// cout << now.x << " " << now.y << "\n";
		rs+=now.x + now.y;
		take[now.idx][k - times[now.idx]] = 0;
		take[now.idx][m - times[now.idx]] = 1;
		if (times[now.idx] != k) {
			times[now.idx]++;
			now.x = x[now.idx][k - times[now.idx]];
			now.y = x[now.idx][m - times[now.idx]];
			pq.push(now);
		}
	}
	vector <val> v;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			if (take[i][j]) {
				v.push_back({x[i][j], i, j});
			}
		}
	}
	sort(v.begin(), v.end());
	for (int i = 0; i < n * k; i++){
		answer[v[i].x][v[i].y] = i % k;
	}
	allocate_tickets(answer);
	return rs;
}
#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...