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 <vector>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
long long find_maximum(int k, vector<vector<int>> x1) {
//cout<<"?\n";
vector<vector<ll> >x;
for(int i=0;i<x1.size();i++)
{
vector<ll>row;
for(int j=0;j<x1[i].size();j++)row.push_back(x1[i][j]);
x.push_back(row);
}
ll n = x.size();
ll m = x[0].size();
vector<vector<int>> answer;
vector<ll>smallest[n];
for(ll i=0;i<n;i++)
{
smallest[i]=x[i];
sort(smallest[i].begin(),smallest[i].end());
}
ll use[n][m];
memset(use,-1,sizeof(use));
vector<ll>small[n];
vector<ll>large[n];
ll ret=0;
vector<pair<ll,pair<ll,ll> > >del;
for(int i=0;i<n;i++)
{
for(int j=0;j<k;j++)
{
ret-=smallest[i][j];
del.push_back({smallest[i][k-j-1]+smallest[i][m-j-1],{i,j}});
}
}
sort(del.rbegin(),del.rend());
int cntsmall[n];
for(int i=0;i<n;i++)cntsmall[i]=k;
for(int i=0;i<n*k/2;i++)
{
ret+=del[i].first;
cntsmall[del[i].second.first]--;
}
for(int i=0;i<n;i++)
{
vector<pair<ll,ll> >sm1;
for(int j=0;j<m;j++)sm1.push_back({x[i][j],j});
sort(sm1.begin(),sm1.end());
for(int j=0;j<cntsmall[i];j++)
{
small[i].push_back(sm1[j].second);
}
for(int j=1;j<=k-cntsmall[i];j++)
{
large[i].push_back(sm1[m-j].second);
}
}
//cout<<dp[n-1][n*k/2]<<endl;
for(ll j=0;j<k;j++)
{
//cout<<j<<endl;
vector<pair<ll,ll> >sizes;
for(ll i=0;i<n;i++)
{
sizes.push_back({small[i].size(),i});
}
sort(sizes.rbegin(),sizes.rend());
for(ll i=0;i<sizes.size();i++)
{
//cout<< " "<<i<<endl;
if(i<n/2)
{
//cout<<" "<<small[sizes[i].second].size()<<endl;
use[sizes[i].second][small[sizes[i].second].back()]=j;
small[sizes[i].second].pop_back();
}
else
{
use[sizes[i].second][large[sizes[i].second].back()]=j;
large[sizes[i].second].pop_back();
}
}
}
for(ll i=0;i<n;i++)
{
vector<int>v;
for(ll j=0;j<m;j++)
{
v.push_back(use[i][j]);
}
answer.push_back(v);
}
allocate_tickets(answer);
return ret;
}
/*
2 3 2
0 2 5
1 1 3
*/
Compilation message (stderr)
tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:9:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
9 | for(int i=0;i<x1.size();i++)
| ~^~~~~~~~~~
tickets.cpp:12:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
12 | for(int j=0;j<x1[i].size();j++)row.push_back(x1[i][j]);
| ~^~~~~~~~~~~~~
tickets.cpp:70:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for(ll i=0;i<sizes.size();i++)
| ~^~~~~~~~~~~~~
# | 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... |