Submission #358575

#TimeUsernameProblemLanguageResultExecution timeMemory
358575JasiekstrzCarnival Tickets (IOI20_tickets)C++17
100 / 100
1038 ms71568 KiB
#include "tickets.h" #include<bits/stdc++.h> using namespace std; long long find_maximum(int k, vector<vector<int>> x) { int n = x.size(); int m = x[0].size(); int i,j; vector<int> it; vector<int> cnt[2]; vector<vector<int>> ans; vector<pair<int,int>> pq; long long w=0; for(i=0;i<n;i++) it.push_back(m-1); for(i=0;i<n;i++) { ans.push_back({}); for(j=0;j<m;j++) ans.back().push_back(-1); } for(i=0;i<n;i++) { for(j=0;j<k;j++) w-=x[i][j]; } for(i=0;i<n;i++) { for(j=m-1;j>=m-k;j--) pq.push_back({-x[i][j]-x[i][j-m+k],i}); } sort(pq.begin(),pq.end()); for(i=0;i<k*n/2;i++) { w-=pq[i].first; it[pq[i].second]--; } for(i=0;i<n;i++) { cnt[0].push_back(m-1-it[i]); cnt[1].push_back(k-cnt[0].back()); } while(k--) { vector<pair<int,int>> mx; for(i=0;i<n;i++) mx.push_back({-cnt[0][i],i}); sort(mx.begin(),mx.end()); for(i=0;i<n/2;i++) ans[mx[i].second][m-1-(--cnt[0][mx[i].second])]=k; for(i=n/2;i<n;i++) ans[mx[i].second][--cnt[1][mx[i].second]]=k; } allocate_tickets(ans); return w; }
#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...