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;
/*
void allocate_tickets(vector<vector<int>> arr) {
for(auto v : arr) {
for(auto n : v) {
cout << n << " ";
}
cout << "\n";
}
cout << endl;
}
*/
long long find_maximum(int K, vector<vector<int>> arr) {
int N = arr.size();
int M = arr[0].size();
int G = M - K;
long long ans = 0;
vector<vector<int>> ret;
vector<vector<int>> typ;
ret.resize(N);
typ.resize(N);
priority_queue<pair<int, pair<int, int>>> pq;
for(int i = 0; i < N; i++) {
ret[i].resize(M, -1);
typ[i].resize(M);
for(int j = M - 1; j >= M - K; j--) {
ans += arr[i][j];
pq.push(make_pair(-arr[i][j] - arr[i][j-G], make_pair(i, j)));
typ[i][j] = 1;
}
}
int tot = N * K / 2;
while(tot--) {
auto p = pq.top();
ans += p.first;
typ[p.second.first][p.second.second] = 0;
typ[p.second.first][p.second.second-G] = -1;
pq.pop();
}
vector<pair<int, int>> cnt(N);
vector<int> tkn(N);
for(int i = 0; i < N; i++) {
int c = 0;
for(int j = 0; j < M; j++) {
if(typ[i][j] == 1) {
c++;
}
}
cnt[i] = make_pair(c, i);
}
for(int k = 0; k < K; k++) {
sort(cnt.begin(), cnt.end());
for(int n = 0; n < N / 2; n++) {
auto p = cnt[n];
ret[p.second][k - tkn[p.second]] = k;
}
for(int n = N/2; n < N; n++) {
pair<int,int>& p = cnt[n];
//cout << p.second << " " << M-1-tkn[p.second] << endl;
ret[p.second][M-1-tkn[p.second]] = k;
tkn[p.second]++;
p.first--;
}
}
allocate_tickets(ret);
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... |