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 <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
struct node
{
long long int id,val;
}tmp[100005];
struct cmp{
bool operator ()(node x,node y)
{
return x.val>y.val;
}
};
long long int ans[1505][1505],a[10005],p2[10005],tag[100005],mi[100005],ma,l[100005],r[100005],p[100005];
long long find_maximum(int k, std::vector<std::vector<int>> x) {
int n = x.size();
int m = x[0].size();
long long int sum=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
ans[i][j]=-1;
}
l[i]=0;
p[i]=0;
p2[i]=m-1;
r[i]=m-k;
}
for(int cnt=1;cnt<=k;cnt++)
{
for(int i=0;i<n;i++)
{
sum+=x[i][m-cnt];
}
}
for(int i=0;i<n;i++)
{
tmp[i].id=i;
tmp[i].val=x[i][r[i]]+x[i][l[i]];
push_heap(tmp,tmp+i+1,cmp());
}
int num=n;
for(int le=0;le<k*n/2;le++)
{
pop_heap(tmp,tmp+num,cmp());
//cout<<le<<endl;
//for(int i=0;i<n;i++)cout<<tmp[i].id<<" "<<tmp[i].val<<endl;
sum-=tmp[num-1].val;
l[tmp[num-1].id]++;
r[tmp[num-1].id]++;
//cout<<tmp[num-1].id<<" "<<tmp[num-1].val<<endl;
if(r[tmp[num-1].id]==m)num--;
else
{
tmp[num-1].val=x[tmp[num-1].id][l[tmp[num-1].id]]+x[tmp[num-1].id][r[tmp[num-1].id]];
push_heap(tmp,tmp+num,cmp());
}
}
for(int cnt=0;cnt<k;cnt++)
{
int count=0;
for(int i=0;i<n;i++)tag[i]=0;
for(int i=0;i<n;i++)
{
if(p2[i]<r[i])
{
ans[i][p[i]]=cnt;
p[i]++;
tag[i]=1;
count++;
}
if(count==n/2)break;
}
for(int i=0;i<n;i++)
{
if(count==n/2)break;
if(tag[i]==1)continue;
if(p[i]<l[i])
{
ans[i][p[i]]=cnt;
p[i]++;
tag[i]=1;
count++;
}
}
for(int i=0;i<n;i++)
{
if(tag[i]==0)
{
ans[i][p2[i]]=cnt;
p2[i]--;
}
}
}
std::vector<std::vector<int>> answer;
for (int i = 0; i < n; i++) {
std::vector<int> row(m);
for(int j=0;j<m;j++)
{
row[j]=ans[i][j];
if(ans[i][j]==0)a[i]=x[i][j];
}
answer.push_back(row);
}
allocate_tickets(answer);
return sum;
}
# | 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... |