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)
{
long long value = 0;
for (size_t i = 0; i < x.size(); i++)
for (size_t j = 0; j < k; j++)
value -= x[i][j];
vector<size_t> y(x.size(), k);
priority_queue<pair<int64_t, size_t>> q;
for (size_t i = 0; i < x.size(); i++)
q.emplace(x[i][k - 1] + x[i].back(), i);
for (size_t z = 0; z < x.size() * k / 2; z++)
{
auto const [d, i] = q.top();
q.pop();
value += d;
y[i]--;
if (y[i])
q.emplace(x[i][y[i] - 1] + x[i][x[i].size() - (k - y[i] + 1)], i);
}
vector<vector<int>> a(x.size(), vector<int>(x[0].size(), -1));
priority_queue<pair<size_t, size_t>> q_low, q_up;
for (size_t i = 0; i < k; i++)
q_low.emplace(x.size() / 2, i), q_up.emplace(x.size() / 2, i);
for (size_t i = 0; i < x.size(); i++)
{
for (size_t j = 0; j < y[i]; j++)
{
auto const [low, h] = q_low.top();
q_low.pop();
a[i][j] = h;
if (low - 1)
q_low.emplace(low - 1, h);
}
for (size_t j = x[i].size() - (k - y[i]); j < x[i].size(); j++)
{
auto const [up, h] = q_up.top();
q_up.pop();
a[i][j] = h;
if (up - 1)
q_up.emplace(up - 1, h);
}
}
allocate_tickets(a);
return value;
}
Compilation message (stderr)
tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:9:30: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
9 | for (size_t j = 0; j < k; j++)
| ~~^~~
tickets.cpp:29:26: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
29 | for (size_t i = 0; i < k; i++)
| ~~^~~
# | 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... |