Submission #1063057

#TimeUsernameProblemLanguageResultExecution timeMemory
1063057jamjanekCarnival Tickets (IOI20_tickets)C++14
0 / 100
1 ms348 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; long long find_maximum(int k, std::vector<std::vector<int>> x) { int n = x.size(); int m = x[0].size(); int i, j; vector<vector<int>>answer = x; for(i=0;i<n;i++) for(j=0;j<m;j++) answer[i][j] = -1; long long wynik = 0; priority_queue<pair<long long, pair<int, int>>>kolejka; vector<set<int>>dodatnie(n), ujemne(n); for(i=0;i<n;i++){ for(j=m-k;j<m;j++){ wynik+=x[i][j]; dodatnie[i].insert(j); } if(k<m){ kolejka.push({-(long long)x[i][m-k]-x[i][0], {i, 0}}); } } for(int minus=0;minus<k*n/2;minus++){ i = kolejka.top().second.first; j = kolejka.top().second.second; wynik+=kolejka.top().first; kolejka.pop(); ujemne[i].insert(j); j++; dodatnie[i].erase(j+m-k); if(j<k) kolejka.push({-(long long)x[i][m-k+j]-x[i][j], {i,j}}); }//0011111 //1111100 int bilans = 0; for(i=0;i<k;i++){ for(j=0;j<n;j++){ if(dodatnie[j].size()>ujemne[j].size() || (dodatnie[j].size()==ujemne[j].size() && bilans>=0)){ auto it = *dodatnie[j].begin(); answer[j][it] = i; bilans++; dodatnie[j].erase(it); } else{ auto it = *ujemne[j].begin(); answer[j][it] = i; bilans--; ujemne[j].erase(it); } } } allocate_tickets(answer); return wynik; }
#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...