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 <cassert>
#include <cstdio>
#include <vector>
#include <string>
#include <bits/stdc++.h>
using namespace std;
int fr[1505];
long long sumtot[1505];
deque <pair <int,int> > ceaules[1505];
vector <vector <int> > matrfin;
bool compare(int a,int b)
{
return ceaules[a].front().first+ceaules[a].back().first<ceaules[b].front().first+ceaules[b].back().first||(ceaules[a].front().first+ceaules[a].back().first==ceaules[b].front().first+ceaules[b].back().first&&sumtot[a]<sumtot[b]);
}
long long find_maximum(int k, std::vector<std::vector<int>> x)
{
int i,j;
int n = x.size();
int m = x[0].size();
for (i=0; i<n; i++)
{
for (j=0; j<m; j++)
{
sumtot[i]+=x[i][j];
ceaules[i].push_back({x[i][j],j});
}
}
matrfin.resize(n);
for (i=0;i<n;i++)
{
matrfin[i].resize(m);
}
long long solfin=0;
for (i=1; i<=k; i++)
{
vector <int> bonjour;
for (j=0; j<n; j++)
{
fr[j]=0;
bonjour.push_back(j);
}
sort (bonjour.begin(),bonjour.end(),compare);
long long sum=0;
for (j=0;j<n/2;j++)
{
sum=sum-ceaules[bonjour[j]].front().first;
sumtot[j]-=ceaules[bonjour[j]].front().first;
matrfin[bonjour[j]][ceaules[bonjour[j]].front().second]=i;
ceaules[bonjour[j]].pop_front();
}
for (j=n/2;j<n;j++)
{
sum=sum+ceaules[bonjour[j]].back().first;
sumtot[j]-=ceaules[bonjour[j]].back().first;
matrfin[bonjour[j]][ceaules[bonjour[j]].back().second]=i;
ceaules[bonjour[j]].pop_back();
}
solfin=solfin+sum;
}
for (i=0;i<n;i++)
{
for (j=0;j<m;j++)
{
matrfin[i][j]--;
}
}
allocate_tickets(matrfin);
return solfin;
}
#ifdef HOME
static int n;
static int m;
static int k;
static std::vector<std::vector<int>> d;
static std::vector<std::vector<int>> x;
static int called = 0;
static void check(bool cond, std::string message)
{
if (!cond)
{
printf("%s\n", message.c_str());
exit(0);
}
}
void allocate_tickets( std::vector<std::vector<int>> _d)
{
check(!called, "allocate_tickets called more than once");
d = _d;
check((int)d.size() == n, "allocate_tickets called with parameter of wrong size");
for (int i = 0; i < n; i++)
{
check((int)d[i].size() == m, "allocate_tickets called with parameter of wrong size");
}
called = 1;
}
int main()
{
assert(scanf("%d %d %d", &n, &m, &k) == 3);
x.resize(n);
for (int i = 0; i < n; i++)
{
x[i].resize(m);
for (int j=0; j < m; j++)
{
assert(scanf("%d", &x[i][j]) == 1);
}
}
fclose(stdin);
long long answer = find_maximum(k, x);
check(called, "failure to call allocate_tickets");
printf("%lld\n", answer);
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if (j) printf(" ");
printf("%d", d[i][j]);
}
printf("\n");
}
fclose(stdout);
return 0;
}
#endif // HOME
# | 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... |