Submission #850682

#TimeUsernameProblemLanguageResultExecution timeMemory
850682abcvuitunggioCarnival Tickets (IOI20_tickets)C++17
100 / 100
607 ms88260 KiB
#include "tickets.h" #include <vector> #include <bits/stdc++.h> using namespace std; long long find_maximum(int k, vector <vector <int>> x) { int n=x.size(),m=x[0].size(); int idx[n]; long long res=0; vector <vector <int>> answer; vector <int> v[n]; priority_queue <pair <int, int>> q; answer.resize(n); for (int i=0;i<n;i++){ idx[i]=k; answer[i].resize(m,-1); for (int j=k-1;j>=0;j--){ res-=x[i][j]; v[i].push_back(x[i][m-j-1]+x[i][k-j-1]); } q.push({v[i].back(),i}); } for (int i=0;i<n*k/2;i++){ res+=q.top().first; idx[q.top().second]--; v[q.top().second].pop_back(); q.push({v[q.top().second].back(),q.top().second}); q.pop(); } vector <pair <int, int>> ve; for (int i=0;i<k;i++){ ve.clear(); for (int j=0;j<n;j++) ve.push_back({idx[j],j}); sort(ve.begin(),ve.end()); for (int j=0;j<n/2;j++){ x[ve[j].second].pop_back(); answer[ve[j].second][x[ve[j].second].size()]=i; } for (int j=n/2;j<n;j++){ idx[ve[j].second]--; answer[ve[j].second][idx[ve[j].second]]=i; } } allocate_tickets(answer); return res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...