#include<bits/stdc++.h>
#include "tickets.h"
#include <vector>
#define ll long long
using namespace std;
const long long N = 1510;
vector <vector <int>> x;
long long n, m, k;
long long l[N], r[N];
long long cnt[N];
long long ans[N][N];
vector <vector <int>> answer;
void solve(){
memset(ans, -1, sizeof ans);
vector<array <long long, 3>> valores;
for(long long i = 0;i < n;i++){
cnt[i] = 0;
for(long long j = 0;j <= l[i];j++){
valores.push_back({x[i][j], i, j});
}
for(long long j = r[i];j < m;j++){
valores.push_back({x[i][j], i, j});
}
}
sort(valores.begin(), valores.end());
for(long long i = 0;i < (n/2)*k;i++){
cnt[valores[i][1]]++;
}
long long res = 0;
long long turno = 0;
for(long long i = 0;i < n;i++){
r[i] = m-1;
l[i] = 0;
}
for(long long i = 0;i < k;i++){
vector <pair <long long, long long>> contadores;
for(long long i = 0;i < n;i++){
contadores.push_back({cnt[i], i});
}
sort(contadores.begin(), contadores.end());
for(long long i = 0;i < n/2;i++){
swap(contadores[i].first, contadores[i].second);
ans[contadores[i].first][r[contadores[i].first]] = turno;
res += x[contadores[i].first][r[contadores[i].first]];
r[contadores[i].first]--;
}
for(long long i = n/2;i < n;i++){
swap(contadores[i].first, contadores[i].second);
ans[contadores[i].first][l[contadores[i].first]] = turno;
res -= x[contadores[i].first][l[contadores[i].first]];
l[contadores[i].first]++;
cnt[contadores[i].first]--;
}
turno++;
}
for(long long i = 0;i < n;i++){
vector <int> aux;
for(long long j = 0;j < m;j++){
aux.push_back(ans[i][j]);
}
answer.push_back(aux);
}
allocate_tickets(answer);
}
long long find_maximum(int kk, std::vector<std::vector<int>> xx) {
x = xx;
memset(ans, -1, sizeof ans);
n = x.size();
m = x[0].size();
k = kk;
set <pair <int, int>> s;
long long res = 0;
for(long long i = 0;i < n;i++){
l[i] = k-1;
r[i] = m;
for(long long j = 0;j < m;j++){
if(j < k) res -= x[i][j];
if(j == k-1){
s.insert({+x[i][j]+x[i][m-1], i});
}
}
}
for(int j = 0;j < (n*k)/2;j++){
auto it = s.end();
it--;
auto [valor, pos] = *it;
s.erase(it);
res += valor;
l[pos]--;
r[pos]--;
if(l[pos] >= 0) s.insert({+x[pos][l[pos]] + x[pos][r[pos]-1], pos});
}
solve();
return res;
}
# | 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... |