Submission #318423

#TimeUsernameProblemLanguageResultExecution timeMemory
318423nickmet2004Carnival Tickets (IOI20_tickets)C++14
100 / 100
961 ms62468 KiB
#include<bits/stdc++.h> #include "tickets.h" using namespace std; int cnt[1505]; long long find_maximum(int k , vector<vector<int>> a){ int n = a.size() , m = a[0].size(); /// nk/2 maximums - nk/2 minimums priority_queue<pair<int , int>> pq; long long ans = 0; for(int i = 0; i < n; ++i){ for(int j = 0; j < k; ++j) ans += a[i][m - k + j] ,pq.emplace(-a[i][j] - a[i][m - k + j] , i); } for(int i = 0; i < n * k / 2; ++i) {auto x = pq.top(); pq.pop(); cnt[x.second]++, ans += x.first;} vector<vector<int>> r(n , vector<int>(m , -1)); /// nk/2 divide into n/2 groups int mnL = 0 , mxR = 0; for(int i = 0; i < n; ++i){ for(int j = 0; j < cnt[i]; ++j) r[i][j] = mnL++ , mnL%= k; mxR = mnL; for(int j = m - k + cnt[i]; j < m; ++j) r[i][j] = mxR++ , mxR%= k; } allocate_tickets(r); return ans; }
#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...