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 <bits/stdc++.h>
#ifndef SKY
#include "tickets.h"
#endif // SKY
using namespace std;
#define N 1510
#define ll long long
#define fs first
#define sc second
#define ii pair<ll,int>
#define pb push_back
int n,m;
deque<ii>cost[N];
#ifdef SKY
void allocate_tickets(vector<vector<int>>kq)
{
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
cout<<kq[i][j]<<" ";
cout<<endl;
}
}
#endif // SKY
bool SS(const int&u,const int&v)
{
return cost[u].front().fs+cost[u].back().fs<cost[v].front().fs+cost[v].back().fs;
}
ll find_maximum(int k, vector<vector<int>> xxx)
{
n=xxx.size();
m=xxx[0].size();
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
cost[i].pb({xxx[i][j],j});
vector<int>s;
for(int i=0;i<n;i++)
s.pb(i);
vector<vector<int>>kq;
kq.resize(n,vector<int>(m,-1));
ll res=0;
for(int t=0;t<k;t++)
{
sort(s.begin(),s.end(),SS);
for(int i=0;i<n;i++)
if(i*2<n)
{
res-=cost[s[i]].front().fs;
kq[s[i]][cost[s[i]].front().sc]=t;
cost[s[i]].pop_front();
}else
{
res+=cost[s[i]].back().fs;
kq[s[i]][cost[s[i]].back().sc]=t;
cost[s[i]].pop_back();
}
}
allocate_tickets(kq);
return res;
}
#ifdef SKY
int main()
{
freopen("A.inp","r",stdin);
freopen("A.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int n,m,k;
cin>>n>>m>>k;
vector<vector<int>>x;
x.resize(n,vector<int>(m,0));
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
cin>>x[i][j];
cout<<find_maximum(k,x);
return 0;
}
#endif
# | 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... |