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;
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));
vector<int> numMinus(n, k);
priority_queue<pair<int, int>> pq;
for(int i = 0; i < n; i++)
pq.push({x[i][numMinus[i] - 1] + x[i][m - k + numMinus[i] - 1], i});
for(int i = 0; i < k * n / 2; i++){
int row = pq.top().second;
pq.pop();
numMinus[row]--;
if (numMinus[row] > 0)
pq.push({x[row][numMinus[row] - 1] + x[row][m - k + numMinus[row] - 1], row});
}
int plusPtr = 0, minusPtr = k - 1;
long long total = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j < numMinus[i]; j++){
answer[i][j] = minusPtr;
minusPtr = (minusPtr == 0? k - 1 : minusPtr - 1);
total -= x[i][j];
}
for(int j = m - k + numMinus[i]; j < m; j++){
answer[i][j] = plusPtr;
plusPtr = (plusPtr == k - 1? 0 : plusPtr + 1);
total += x[i][j];
}
}
allocate_tickets(answer);
return total;
}
# | 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... |