#include <bits/stdc++.h>
using namespace std;
#include "tickets.h"
long long find_maximum(int k, vector<vector<int>> x) {
int n = x.size();
int m = x[0].size();
vector<vector<int>> answer(n, vector<int>(m, -1));
if (m == 1) {
assert(k == 1);
vector<int> elements;
for (int i(0); i < n; ++i) {
answer[i][0] = 0;
elements.push_back(x[i][0]);
}
allocate_tickets(answer);
long long ans = 0;
sort(elements.begin(), elements.end());
int mid = elements[n / 2];
for (int v : elements)
ans += abs(mid - v);
return ans;
} else if (k == 1) {
vector<pair<int, int>> pairs(n);
vector<bool> pickSide;
long long sol = -1;
for (int i(0); i < n; ++i)
pairs[i] = make_pair(x[i][0], x[i].back());
auto calcAns = [&](int mediane) {
priority_queue<pair<int, int>> bstRemoved;
vector<bool> side(n);
long long curSol = 0;
int neededRight = n / 2;
for (int i(0); i < n; ++i) {
if (pairs[i].second < mediane) {
curSol += mediane - pairs[i].first;
continue;
}
curSol += pairs[i].second - mediane;
side[i] = 1;
if (pairs[i].first > mediane)
neededRight--;
else
bstRemoved.emplace(2 * mediane - (pairs[i].first + pairs[i].second),
i);
while ((int)bstRemoved.size() > neededRight) {
auto [delta, pos] = bstRemoved.top();
bstRemoved.pop();
curSol += delta;
side[pos] = 0;
}
}
int cnt = 0;
for (auto v : side)
cnt += v;
if (cnt == n / 2 and curSol > sol)
sol = curSol, pickSide = move(side);
};
for (auto [med1, med2] : pairs)
calcAns(med1), calcAns(med2);
for (int i(0); i < n; ++i) {
if (pickSide[i])
answer[i].back() = 0;
else
answer[i][0] = 1;
}
allocate_tickets(answer);
return sol;
}
allocate_tickets(answer);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Ticket 0 of color 0 is played on invalid day 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
There is no ticket of color 0 on day 0 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
There is no ticket of color 0 on day 0 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
324 KB |
There is no ticket of color 0 on day 0 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
324 KB |
There is no ticket of color 0 on day 0 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
588 KB |
Output is correct |
7 |
Incorrect |
1 ms |
204 KB |
Ticket 0 of color 0 is played on invalid day 1 |
8 |
Halted |
0 ms |
0 KB |
- |