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 <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>> answer(n, vector<int> (m, -1));
int timer = 0;
long long sum = 0;
vector<int> l(n, 0), r(n, 0), rr(n, 0);
for(int i = 0; i < n; i ++) {
l[i] = 0;
r[i] = m - 1 - k + 1;
timer += k;
for(int j = 0; j < k; j ++)
sum += x[i][m - 1 - j];
}
for(int i = 0; i < n; i ++) rr[i] = m - 1;
priority_queue<array<int, 2>> pq;
for(int i = 0; i < n; i ++) {
int L = l[i];
int R = r[i];
pq.push({- x[i][L] - x[i][R], i});
}
while(!pq.empty() && timer > k * n / 2) {
int c = pq.top()[0];
int i = pq.top()[1];
pq.pop();
sum += c;
l[i] ++ ;
r[i] ++ ;
timer --;
if(r[i] < m) {
int L = l[i];
int R = r[i];
pq.push({- x[i][L] - x[i][R], i});
}
}
for(int j = 0; j < k; j ++) {
vector<array<int, 3>> p;
for(int i = 0; i < n; i ++) {
if(l[i] > 0) p.push_back({x[i][l[i] - 1], i, 0});
if(rr[i] >= r[i]) p.push_back({x[i][rr[i]], i, 1});
}
sort(p.begin(), p.end());
reverse(p.begin(), p.end());
vector<int> mark(n, 0);
int cnt = 0, _cnt = 0;
for(auto [c, i, type] : p) {
if(mark[i]) continue ;
if(type == 0 && cnt < n / 2) {
cnt ++ ;
mark[i] = true;
answer[i][l[i] - 1] = j;
l[i] -- ;
}
if(type == 1 && _cnt < n / 2) {
_cnt ++ ;
mark[i] = true;
answer[i][rr[i]] = j;
rr[i] -- ;
}
}
}
allocate_tickets(answer);
return sum;
}
Compilation message (stderr)
tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:67:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
67 | for(auto [c, i, type] : p) {
| ^
# | 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... |