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>
#define PB push_back
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define i2 array<int,2>
using namespace std;
typedef long long ll;
const int N = 1600;
const ll OO = 1e18;
priority_queue<i2> pq;
int ptr[N];
long long find_maximum(int k, vector<vector<int>> x) {
int n = x.size();
int m = x[0].size();
vector<vector<int>> answer;
for (int i = 0; i < n; i++) {
std::vector<int> row(m);
fill(all(row), -1);
answer.push_back(row);
}
ll ans = 0;
for (int i = 0; i < n; i++){
for (int j = 0; j < k; j++){
answer[i][m - k + j] = j;
ans += x[i][m - k + j];
}
ptr[i] = 0;
pq.push({-x[i][m - k] - x[i][0], i});
// cerr << -x[i][m - k] - x[i][0] << " " << i << '\n';
}
// add again to pq only if ptr < m
for (int itr = (n / 2) * k; itr > 0; itr--){
i2 now = pq.top(); pq.pop();
ans += now[0];
int id = now[1];
answer[id][m - k + ptr[id]] = -1;
answer[id][ptr[id]] = ptr[id];
ptr[id]++;
if (ptr[id] < k){
pq.push({-x[id][m - k + ptr[id]] - x[id][ptr[id]], id});
}
}
allocate_tickets(answer);
return ans;
}
# | 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... |