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 <bits/stdc++.h>
#include "tickets.h"
using namespace std;
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define mt make_tuple
typedef tuple<int, int, int> tiii;
typedef long long lld;
lld find_maximum(int K, vector<vector<int>> A)
{
int N = A.size();
int M = A[0].size();
lld ans = 0;
vector<vector<int>> answer(N, vector<int>(M, -1));
priority_queue <tiii> que;
for (int i=0;i<N;i++){
for (int k=0;k<K;k++) ans -= A[i][k], answer[i][k] = -2;
que.push(mt(A[i][M-1]+A[i][K-1], i, M-1));
}
for (int k=0;k<K;k++){
queue <tiii> todo;
for (int i=0;i<N;i+=2){
auto t = que.top(); que.pop();
auto [v, p, q] = t;
answer[p][K-(M-q)] = -1; answer[p][q] = k;
ans += v;
if (M-q > k && q > 0) todo.push(mt(A[p][q-1]+A[p][K-(M-q)-1], p, q-1));
else if (q > 0) que.push(mt(A[p][q-1]+A[p][K-(M-q)-1], p, q-1));
}
while (!todo.empty()){
auto q = todo.front(); todo.pop();
que.push(q);
}
}
for (int i=0;i<N;i++){
// for (int j=0;j<M;j++) debug("%d ", answer[i][j]); debug("\n");
vector <bool> vis(K, 0);
for (int j=M,k=K-1;j--;){
if (answer[i][j] >= 0) vis[answer[i][j]] = 1;
else if (answer[i][j] == -2){
while (k >= 0 && vis[k]) k--;
assert(k >= 0);
answer[i][j] = k;
}
}
}
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... |