# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
921257 | ksujay2 | Carnival Tickets (IOI20_tickets) | C++17 | 0 ms | 0 KiB |
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 <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<vector<ll>> delta(n, vector<ll>(k));
ll sm = 0;
for(int i = 0; i < n; i++) {
for(int j = 0; j < k; j++) {
sm -= x[i][j];
}
for(int j = 0; j < k; j++) {
delta[i][j] = x[i][m - j - 1] + x[i][k - j - 1];
}
}
vector<int> pos(n), neg(n, k);
priority_queue<pair<ll, int>> pq;
for(int i = 0; i < n; i++) {
pq.push({delta[i][pos[i]], i});
}
for(int i = 0; i < n / 2 * k; i++) {
sm += pq.top().first;
int j = pq.top().second;
pq.pop();
pos[j]++;
neg[j]--;
if(pos[j] < k) pq.push({delta[j][pos[j]], j});
}
vector<vector<int>> s(n, vector<int>(m, -1));
for(int i = 0; i < k; i++) {
int negcnt = 0;
vector<bool> used(n);
for(int j = 0; j < n; j++) {
if(pos[j] == 0) {
used[j] = true;
neg[j]--;
s[j][neg[j]] = i;
negcnt++;
}
}
for(int j = 0; j < n; j++) {
if(used[j]) continue;
if(negcnt < n / 2 && neg[j] > 0) {
neg[j]--;
s[j][neg[j]] = i;
negcnt++;
} else {
s[j][m - pos[j]] = i;
pos[j]--;
}
}
}
allocate_tickets(s);
return sm;
}
int main() {
cout << find_maximum(1, {{0, 0, 1, 0},{1, 1, 0, 0}, {0, 1, 1, 1}, {0,1,1,0}}) << endl;
}