| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1348527 | Faisal_Saqib | Carnival Tickets (IOI20_tickets) | C++17 | 0 ms | 0 KiB |
#include "tickets.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1501;
int cnt[N];
vector<int> add[N],mns[N];
long long find_maximum(int k, std::vector<std::vector<int>> x) {
int n = x.size();
int m = x[0].size();
std::vector<std::vector<int>> answer;
vector<pair<int,int>> full;
for (int i = 0; i < n; i++) {
cnt[i]=0;
add[i].clear();
mns[i].clear();
std::vector<int> row(m,-1);
for(int j=0;j<m;j++)
{
use[i][j]=0;
full.push_back({x[i][j],i*m+j});
}
answer.push_back(row);
}
sort(begin(full),end(full));
// we need to take maximum n/2 *k
ll ans=0;
int tot=n/2 * k;
for(int i=full.size()-1;i>=0;i--)
{
int col=full[i].second/m;
if(cnt[col]<k and tot>0)
{
tot--;
ans+=full[i].first;
cnt[col]++;
add[col].push_back(full[i].second%m);
}
}
tot=n/2 * k;
for(int i=0;i<full.size();i++)
{
int col=full[i].second/m;
if(cnt[col]<k and tot>0)
{
tot--;
ans-=full[i].first;
cnt[col]++;
mns[col].push_back(full[i].second%m);
}
}
int l=0;
for(int i=0;i<n;i++)
{
for(auto j:add[i])
{
answer[i][j]=(l++)%k;
}
int r=l;
for(auto j:mns[i])
{
answer[i][j]=(r++)%k;
}
}
allocate_tickets(answer);
return ans;
}
