# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
432729 | Enkognit | Carnival Tickets (IOI20_tickets) | C++14 | 1475 ms | 140652 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 ll long long
#define mp make_pair
#define pb push_back
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fi first
#define se second
#define all(v) v.begin(),v.end()
using namespace std;
ll qq[100005];
vector<vector<pll> > a;
vector<ll> mn[100005], mx[100005];
long long find_maximum(int k, std::vector<std::vector<int>> x) {
int n = x.size();
int m = x[0].size();
std::vector<std::vector<int> > answer;
set<pll> s;
for (int i = 0; i < n; i++)
{
vector<pll> vv;
for (int j = 0; j < m; j++)
vv.pb(mp(x[i][j], j));
qq[i]=k;
sort(all(vv));
a.pb(vv);
//cout << i << " : " << a[i].back().fi << " " << a[i][qq[i]-1].fi << "\n";
s.insert(mp(-(a[i].back().fi+a[i][qq[i]-1].fi), i));
}
for (int i = 0; i < k*n/2; i++)
{
pll x=*s.begin();
s.erase(s.begin());
//cout << x.fi << " " << x.se << "\n";
qq[x.se]--;
if (qq[x.se]>0)
{
s.insert(mp(-(a[x.se][a[x.se].size()-(k-qq[x.se])-1].fi+a[x.se][qq[x.se]-1].fi), x.se));
}
}
//cout << "---\n";
answer.resize(n);
for (int i = 0; i < n; i++)
{
answer[i].resize(m, -1);
for (int j = 0; j < a[i].size(); j++)
if (j<qq[i]) mn[i].pb(a[i][j].se); else
if (j>=a[i].size()-(k-qq[i])) mx[i].pb(a[i][j].se);
reverse(all(mn[i]));
//cout << i << " " << mx[i].size() << " " << mn[i].size() << "\n";
}
ll ans=0;
for (int i = 0; i < k; i++)
{
//cout << i << "\n";
vector<pll> vv;
for (int j = 0; j < n; j++)
vv.pb(mp(-mx[j].size(), j));
sort(all(vv));
for (int j = 0; j < n/2; j++)
{
answer[vv[j].se][mx[vv[j].se].back()]=i;
ans+=a[vv[j].se][mx[vv[j].se].back()].fi;
mx[vv[j].se].pop_back();
}
for (int j = n/2; j < n; j++)
{
answer[vv[j].se][mn[vv[j].se].back()]=i;
ans-=a[vv[j].se][mn[vv[j].se].back()].fi;
mn[vv[j].se].pop_back();
}
}
//cout << "---\n";
allocate_tickets(answer);
return ans;
}
/*
4 2 1
5 9
1 4
3 6
2 7
*/
Compilation message (stderr)
# | 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... |