제출 #390552

#제출 시각아이디문제언어결과실행 시간메모리
390552AlexPop28카니발 티켓 (IOI20_tickets)C++14
11 / 100
2 ms716 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; long long find_maximum(int k, vector<vector<int>> x) { int n = x.size(); int m = x[0].size(); vector<vector<int>> ans(n, vector<int>(m, -1)); priority_queue<pair<int, int>> pq; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { pq.emplace(x[i][j], i); } } vector<int> pos(n, m - 1); long long res = 0; for (int it = 0; it < n * m / 2; ++it) { int val, i; tie(val, i) = pq.top(); pq.pop(); if (--pos[i] >= 0) pq.emplace(x[i][pos[i]], i); res += val; } for (int i = 0; i < n; ++i) { for (int j = 0; j <= pos[i]; ++j) { res -= x[i][j]; } } auto zeros = pos; vector<int> pos0(n), pos1(n); for (int i = 0; i < n; ++i) { pos[i] = max(pos[i], -1); pos0[i] = 0; pos1[i] = pos[i] + 1; zeros[i] += 1; } vector<int> order(n); iota(order.begin(), order.end(), 0); for (int it = 0; it < k; ++it) { sort(order.begin(), order.end(), [&](int a, int b) { return zeros[a] > zeros[b]; }); int bal = 0; for (int i : order) { if (bal < n / 2) { ans[i][pos0[i]++] = it; --zeros[i]; ++bal; } else { ans[i][pos1[i]++] = it; } } } allocate_tickets(ans); return res; }
#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...