# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
593586 | keta_tsimakuridze | Carnival Tickets (IOI20_tickets) | C++14 | 2957 ms | 178268 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 "tickets.h"
#include <vector>
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
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<pair<int, int> > v;
vector<int> l(n), r(n);
vector<vector<pii> > b(n);
ll ans = 0;
multiset<pii> s;
vector<int> LF(n);
for(int i = 0; i < n; i++) {
LF[i] = k;
for(int j = 0; j < k; j++) {
ans -= x[i][j];
s.insert({x[i][m - (k - j)] + x[i][j], i});
}
}
for(int i = 0; i < n * k / 2; i++) {
pii x = *--s.end(); s.erase(s.find(x));
ans += x.f;
--LF[x.s];
}
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
if(j < LF[i] || j >= m - (k - LF[i]))
v.push_back({x[i][j], i});
b[i].push_back({x[i][j], j});
}
sort(b[i].begin(), b[i].end());
r[i] = m;
}
sort(v.begin(), v.end());
vector<int> cn(n);
for(int i = 0; i < v.size(); i++) {
if(i < v.size() / 2) cn[v[i].s]--;
else cn[v[i].s]++;
}
vector<vector<int> > u;
u.resize(n, vector<int> (m));
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) u[i][j] = -1;
}
while(k--) {
vector<pii> x;
for(int i = 0; i < n; i++) x.push_back({cn[i], i});
sort(x.begin(), x.end());
for(int i = 0; i < x.size(); i++) {
int id = x[i].s;
if(i < x.size() / 2) {
u[id][b[id][l[id]++].s] = k;
cn[id]++;
} else u[id][b[id][--r[id]].s] = k, cn[id]--;
}
}
allocate_tickets(u);
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |