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;
typedef long long llint;
const int maxn = 1510;
int n, m, k;
llint pref[maxn][maxn];
int t[maxn];
int ptrl[maxn], ptrr[maxn];
bool bio[maxn];
int lef[maxn];
llint f(int x, int t) {
return pref[x][m] - pref[x][m - t] - pref[x][k - t];
}
llint cal(int x, int t) {
if (t == 0) return (1LL << 60);
return f(x, t) - f(x, t - 1);
}
long long find_maximum(int K, std::vector<std::vector<int>> x) {
n = x.size();
m = x[0].size();
k = K;
vector< vector<int> > ans(n, vector<int>(m, -1));
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
pref[i][j + 1] = pref[i][j] + x[i][j];
set< pair<llint, int> > s;
for (int i = 0; i < n; i++) {
t[i] = k;
s.insert({cal(i, k), i});
}
for (int abc = 0; abc < k * n / 2; abc++) {
auto iter = s.begin();
int ind = iter->second;
s.erase(iter);
t[ind]--;
s.insert({cal(ind, t[ind]), ind});
}
//for (int i = 0; i < n; i++) printf("%d ", t[i]);
//printf("\n");
for (int i = 0; i < n; i++) {
lef[i] = k - t[i];
ptrr[i] = 0, ptrr[i] = m - 1;
}
llint sol = 0;
int mid = n / 2;
for (int i = 0; i < k; i++) {
vector< pair<int, int> > v;
for (int j = 0; j < n; j++) {
v.push_back({lef[j], j});
}
sort(v.begin(), v.end());
for (int j = 0; j < n; j++) {
int tr = v[j].second;
if (j >= mid) {
//printf("removing: %d\n", tr);
lef[tr]--;
sol -= x[tr][ptrl[tr]];
ans[tr][ptrl[tr]++] = i;
} else {
//printf("adding: %d\n", tr);
sol += x[tr][ptrr[tr]];
ans[tr][ptrr[tr]--] = i;
}
}
}
allocate_tickets(ans);
return sol;
}
# | 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... |