Submission #416737

#TimeUsernameProblemLanguageResultExecution timeMemory
416737SuhaibSawalha1Carnival Tickets (IOI20_tickets)C++17
27 / 100
2092 ms157212 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; long long calc (vector<long long> &a) { int n = a.size(); long long sum = accumulate(a.begin(), a.end(), 0LL), m = LLONG_MAX, sum2 = 0; sort(a.begin(), a.end()); for (int i = 0; i < n; ++i) { sum -= a[i]; m = min(m, a[i] * i - sum2 + sum - a[i] * (n - i - 1)); sum2 += a[i]; } return m; } long long find_maximum(int k, vector<vector<int>> a) { int n = a.size(); int m = a[0].size(); long long ans = 0; vector<vector<int>> g(n, vector<int>(m, -1)); vector<set<array<int, 2>>> a2(n); set<array<int, 2>, greater<array<int, 2>>> ms; #define ar(i) {- (*a2[i].begin())[0] - (*a2[i].rbegin())[0], i} for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { a2[i].insert({a[i][j], j}); } ms.insert(ar(i)); } for (int kc = 0; kc < k; ++kc) { vector<long long> ask; int t = 0; set<array<int, 2>, greater<array<int, 2>>> ms2; for (auto e : ms) { int v, ind; if (t < n / 2) { v = (*a2[e[1]].begin())[0], ind = (*a2[e[1]].begin())[1]; } else { v = (*a2[e[1]].rbegin())[0], ind = (*a2[e[1]].rbegin())[1]; } ask.push_back(v); g[e[1]][ind] = kc; a2[e[1]].erase({v, ind}); if (kc < k - 1) { ms2.insert(ar(e[1])); } ++t; } ms = ms2; ans += calc(ask); } allocate_tickets(g); 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...