#include "tickets.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1505;
int n, m, cnt0[MAXN], cnt1[MAXN];
vector<vector<int>> ans;
ll total_prize;
bool cmp(int a, int b){
return cnt0[a] < cnt0[b];
}
long long find_maximum(int k, vector<vector<int>> x) {
n = x.size(); m = x[0].size();
ans.assign(n, vector<int>(m, 0));
vector<int> allx;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
allx.push_back(x[i][j]);
}
}
sort(allx.begin(), allx.end());
int mid = allx[allx.size()/2];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if(x[i][j] < mid) cnt0[i]++;
else cnt1[i]++;
}
}
for(int r = 0; r < k; r++){
vector<int> escolhe1, escolhe0, nescolheu;
for(int i = 0; i < n; i++){
if(cnt0[i] == 0){//preciso pegar 1
escolhe1.push_back(i);
}
else if(cnt1[i] == 0){//preciso pegar 0
escolhe0.push_back(i);
}
else nescolheu.push_back(i);
}
sort(nescolheu.begin(), nescolheu.end(), cmp); //quem tem mais 0 doa 0, mais 1 doa 1
for(int e : nescolheu){//da frente eh que tem menos zero
if((int)escolhe1.size() < n/2) escolhe1.push_back(e);
else escolhe0.push_back(e);
}
// cerr << "Rodada " << r << endl;
// cerr << "Escolhi 0 dos: ";
// for(int e : escolhe0) {cerr << e << " ";} cerr << endl;
// cerr << "Escolhi 1 dos: ";
// for(int e : escolhe1) {cerr << e << " ";} cerr << endl;
for(int e : escolhe0){
cnt0[e]--;
ans[e][cnt0[e]] = r;
total_prize += mid-x[e][cnt0[e]];
}
for(int e : escolhe1){
ans[e][m-cnt1[e]] = r;
cnt1[e]--;
total_prize += x[e][m-cnt1[e]]-mid;
}
}
allocate_tickets(ans);
return total_prize;
allocate_tickets(ans);
return 1;
}
| # | 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... |