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 <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <string.h>
#include <math.h>
#include <random>
#include <functional>
#include <assert.h>
#include <math.h>
#define all(x) (x).begin(), (x).end()
#define xx first
#define yy second
using namespace std;
template<typename T, typename Pr = less<T>>
using pq = priority_queue<T, vector<T>, Pr>;
using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;
vector<ii64> ts[1505];
ii trace[1505];
i64 find_maximum(int k, vector<vector<int>> x)
{
int n = x.size();
int m = x[0].size();
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
ts[i].emplace_back(x[i][j], j);
vector<vector<int>> ans(n, vector<int>(m, -1));
i64 ret = 0;
pq<ii64, greater<ii64>> q;
for (int color = 0; color < n; color++)
{
sort(all(ts[color]));
for (int i = m - 1; i >= m - k; i--)
ret += ts[color][i].xx;
trace[color] = ii(0, k);
q.emplace(ts[color][m - k].xx + ts[color][0].xx, color);
}
for (int i = 0; i < k * n / 2; i++)
{
auto [val, c] = q.top();
q.pop();
ret -= val;
trace[c].xx++;
trace[c].yy--;
if (trace[c].xx < k)
q.emplace(ts[c][trace[c].xx].xx + ts[c][m - trace[c].yy].xx, c);
}
int gidx = 0;
for (int color = 0; color < n; color++)
{
for (int i = 0; i < trace[color].xx; i++)
{
ans[color][ts[color][i].yy] = gidx;
gidx = (gidx + 1) % k;
}
int lgi = gidx;
for (int i = 0; i < trace[color].yy; i++)
{
ans[color][ts[color][m - 1 - i].yy] = lgi;
lgi = (lgi + 1) % k;
}
}
allocate_tickets(ans);
return ret;
}
# | 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... |