# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
302709 | Dovran | Carnival Tickets (IOI20_tickets) | C++14 | 0 ms | 0 KiB |
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>
#include "tickets.h"
#define N 2009
#define pii pair <int, int>
#define ff first
#define sz() size()
#define ss second
#define pb push_back
#define ll long long
using namespace std;
int n, m, ans;
pii c[N];
vector<pii> p;
int s[N][N];
int k;
ll find_maximum(int g, vector<vector<int>>v){
k=g;
n=v.sz();
m=v[0].sz();
for(int i=0; i<n ;i++)
c[i]={0, m-1};
while(k){
p.empty();
for(int i=0; i<n; i++)
p.pb({v[i][c[i].ff]+v[i][c[i].ss], i});
sort(p.begin(), p.end());
int x=0, y=0;
for(int i=0; i<n; i++){
int in=p[i].ss;
if(i<n/2)
x+=v[in][c[in].ff], s[in][c[in].ff]=k, c[in].ff++;
else
y+=v[in][c[in].ss], s[in][c[in].ss]=k, c[in].ss++;
}
ans+=y-x;
k--;
}
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
if(s[i][j]==0)
s[i][j]=-1;
else
s[i][j]=g-s[i][j];
}
}
allocate_tickets(s);
return ans;
}
/*
int main(){
int k;
vector<vector<int>>v;
int x, y, z;
cin>>x>>y>>k;
v.resize(x);
for(int i=0; i<x; i++)
for(int j=0; j<y; j++)
cin>>z, v[i].pb(z);
cout<<find_maximum(k, v);
}*/