Submission #947039

#TimeUsernameProblemLanguageResultExecution timeMemory
947039AkibAzmainCarnival Tickets (IOI20_tickets)C++17
11 / 100
1 ms600 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; using ll = long long; long long find_maximum(int k, std::vector<std::vector<int>> arr) { ll n = arr.size(); ll m = arr[0].size(); std::vector<std::vector<int>> ans (n, vector < int > (m, -1)); ll sum = 0; if (m == 1) { vector < pair < ll, ll > > mn (n), mx (n); for (int i = 0; i < n; ++i) { mn[i] = { arr[i][0], i }; mx[i] = { arr[i][m - 1], i }; } sort (mn.begin (), mn.end ()); sort (mx.begin (), mx.end ()); reverse (mx.begin (), mx.end ()); int i = 0, j = 0; vector < bool > v (n); for (int k = 0; k < n / 2; ++k) { while (v[mn[i].second]) ++i; while (v[mx[j].second]) ++j; if (mn[i].second != mx[j].second) { ans[mn[i].second][0] = 0; ans[mx[j].second][m - 1] = 0; sum += mx[j].first - mn[i].first; v[mn[i].second] = v[mx[j].second] = true; } else if (j < n - 1 && mx[j + 1].first - mn[i].first > mx[j].first - mn[i + 1].first) { ans[mn[i].second][0] = 0; ans[mx[j + 1].second][m - 1] = 0; sum += mx[j + 1].first - mn[i].first; v[mn[i].second] = v[mx[j + 1].second] = true; } else { ans[mn[i + 1].second][0] = 0; ans[mx[j].second][m - 1] = 0; sum += mx[j].first - mn[i + 1].first; v[mn[i + 1].second] = v[mx[j].second] = true; } } } allocate_tickets(ans); return sum; }
#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...