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<bits/stdc++.h>
using namespace std;
//void allocate_tickets( std::vector<std::vector<int>> _d);
const int nmax=1500+42;
struct info
{
int i,j;
int diff;
};
vector<info> help;
bool cmp(info a,info b)
{
return a.diff<b.diff;
}
int LHS[nmax];
std::vector<std::vector<int>> positions;
struct line
{
int i,prefix,suffix;
};
vector<line> given;
bool cmp_2(line a,line b)
{
return a.prefix<b.prefix;
}
int days;
int my_n,my_m;
void my_fill()
{
sort(given.begin(),given.end(),cmp_2);
for(int d=0;d<days;d++)
{
sort(given.begin(),given.end(),cmp_2);
for(int j=my_n/2;j<my_n;j++)
{
given[j].prefix--;
positions[given[j].i][given[j].prefix]=d;
}
for(int j=0;j<my_n/2;j++)
{
positions[given[j].i][my_m-given[j].suffix]=d;
given[j].suffix--;
}
}
}
long long find_maximum(int k, std::vector<std::vector<int>> x) {
days=k;
int n = x.size();
int m = x[0].size();
my_n=n;
my_m=m;
long long outp=0;
for (int i = 0; i < n; i++) {
std::vector<int> row(m,-1);
positions.push_back(row);
for(int j=m-k;j<m;j++)
{
outp+=x[i][j];
//cout<<i<<" "<<j<<" -> "<<x[i][j]<<" loss: "<<-x[i][j]-x[i][j-(m-k)]<<endl;
info cur;
cur.i=i;
cur.j=j-(m-k);
cur.diff=x[i][j]+x[i][j-(m-k)];
help.push_back(cur);
}
}
sort(help.begin(),help.end(),cmp);
for(int i=0;i<n/2*k;i++)
{
outp-=help[i].diff;
LHS[help[i].i]++;
}
for(int i=0;i<n;i++)
{
line me;
me.i=i;
me.prefix=LHS[i];
me.suffix=days-LHS[i];
given.push_back(me);
}
my_fill();
allocate_tickets(positions);
return outp;
}
/*
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;
}
*/
# | 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... |