#include "tickets.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
using ll = long long;
using ii = pair<int, int>;
using iii = tuple<int, int, int>;
ll find_maximum(int k, vector<vector<int> > x) {
int n = x.size(), m = x[0].size();
ll ret = 0;
vector<int> num_sub(n, 0);
vector<vector<int> > out(n, vector<int>(m, -1)), add(n), sub(n);
priority_queue<iii> pq;
for (int i = 0; i < n; i++) {
pq.emplace(-x[i][m - k] - x[i][0], i, 0);
}
for (int j = 0; j < n * k / 2; j++) {
auto [_, i, sft] = pq.top();
pq.pop();
num_sub[i]++;
if (sft + 1 < k) {
pq.emplace(-x[i][m - k + sft + 1] - x[i][sft + 1], i, sft + 1);
}
}
for (int i = 0; i < n; i++) {
vector<ii> cur;
for (int j = 0; j < m; j++) {
cur.eb(x[i][j], j);
}
sort(cur.begin(), cur.end());
for (int j = 0; j < num_sub[i]; j++) {
sub[i].pb(cur[j].second);
}
for (int j = m - (k - num_sub[i]); j < m; j++) {
add[i].pb(cur[j].second);
}
}
for (int i = 0; i < k; i++) {
vector<int> ord;
for (int j = 0; j < n; j++) {
ord.pb(j);
}
sort(ord.begin(), ord.end(), [&](const auto &lhs, const auto &rhs) {
return sub[lhs].size() < sub[rhs].size();
});
vector<int> cur;
for (int j = 0; j < n / 2; j++) {
cur.pb(x[ord[j]][add[ord[j]].back()]);
out[ord[j]][add[ord[j]].back()] = i;
add[ord[j]].pop_back();
}
for (int j = n / 2; j < n; j++) {
cur.pb(x[ord[j]][sub[ord[j]].back()]);
out[ord[j]][sub[ord[j]].back()] = i;
sub[ord[j]].pop_back();
}
sort(cur.begin(), cur.end());
for (auto j : cur) {
ret += llabs(j - cur[cur.size() / 2]);
}
}
allocate_tickets(out);
return ret;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
296 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
21 ms |
2508 KB |
Output is correct |
6 |
Correct |
431 ms |
51640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
19 ms |
2900 KB |
Output is correct |
6 |
Correct |
500 ms |
62860 KB |
Output is correct |
7 |
Correct |
539 ms |
66216 KB |
Output is correct |
8 |
Correct |
3 ms |
596 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
5 ms |
980 KB |
Output is correct |
13 |
Correct |
17 ms |
2480 KB |
Output is correct |
14 |
Correct |
20 ms |
2556 KB |
Output is correct |
15 |
Correct |
548 ms |
67928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
432 KB |
Output is correct |
5 |
Correct |
26 ms |
2988 KB |
Output is correct |
6 |
Correct |
4 ms |
724 KB |
Output is correct |
7 |
Correct |
6 ms |
980 KB |
Output is correct |
8 |
Correct |
727 ms |
66332 KB |
Output is correct |
9 |
Correct |
711 ms |
62764 KB |
Output is correct |
10 |
Correct |
703 ms |
61900 KB |
Output is correct |
11 |
Correct |
743 ms |
66396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
444 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
3 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
444 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
3 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
2 ms |
468 KB |
Output is correct |
13 |
Correct |
18 ms |
3156 KB |
Output is correct |
14 |
Correct |
18 ms |
3256 KB |
Output is correct |
15 |
Correct |
24 ms |
3488 KB |
Output is correct |
16 |
Correct |
26 ms |
3924 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
440 KB |
Output is correct |
20 |
Correct |
22 ms |
2992 KB |
Output is correct |
21 |
Correct |
23 ms |
3484 KB |
Output is correct |
22 |
Correct |
24 ms |
3112 KB |
Output is correct |
23 |
Correct |
25 ms |
3620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
852 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
296 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
21 ms |
2508 KB |
Output is correct |
12 |
Correct |
431 ms |
51640 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
19 ms |
2900 KB |
Output is correct |
18 |
Correct |
500 ms |
62860 KB |
Output is correct |
19 |
Correct |
539 ms |
66216 KB |
Output is correct |
20 |
Correct |
3 ms |
596 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
5 ms |
980 KB |
Output is correct |
25 |
Correct |
17 ms |
2480 KB |
Output is correct |
26 |
Correct |
20 ms |
2556 KB |
Output is correct |
27 |
Correct |
548 ms |
67928 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
2 ms |
432 KB |
Output is correct |
32 |
Correct |
26 ms |
2988 KB |
Output is correct |
33 |
Correct |
4 ms |
724 KB |
Output is correct |
34 |
Correct |
6 ms |
980 KB |
Output is correct |
35 |
Correct |
727 ms |
66332 KB |
Output is correct |
36 |
Correct |
711 ms |
62764 KB |
Output is correct |
37 |
Correct |
703 ms |
61900 KB |
Output is correct |
38 |
Correct |
743 ms |
66396 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
2 ms |
340 KB |
Output is correct |
41 |
Correct |
2 ms |
468 KB |
Output is correct |
42 |
Correct |
2 ms |
468 KB |
Output is correct |
43 |
Correct |
2 ms |
444 KB |
Output is correct |
44 |
Correct |
2 ms |
468 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
3 ms |
468 KB |
Output is correct |
48 |
Correct |
2 ms |
468 KB |
Output is correct |
49 |
Correct |
2 ms |
468 KB |
Output is correct |
50 |
Correct |
2 ms |
468 KB |
Output is correct |
51 |
Correct |
18 ms |
3156 KB |
Output is correct |
52 |
Correct |
18 ms |
3256 KB |
Output is correct |
53 |
Correct |
24 ms |
3488 KB |
Output is correct |
54 |
Correct |
26 ms |
3924 KB |
Output is correct |
55 |
Correct |
1 ms |
340 KB |
Output is correct |
56 |
Correct |
2 ms |
468 KB |
Output is correct |
57 |
Correct |
1 ms |
440 KB |
Output is correct |
58 |
Correct |
22 ms |
2992 KB |
Output is correct |
59 |
Correct |
23 ms |
3484 KB |
Output is correct |
60 |
Correct |
24 ms |
3112 KB |
Output is correct |
61 |
Correct |
25 ms |
3620 KB |
Output is correct |
62 |
Correct |
48 ms |
8396 KB |
Output is correct |
63 |
Correct |
50 ms |
8444 KB |
Output is correct |
64 |
Correct |
72 ms |
10040 KB |
Output is correct |
65 |
Correct |
242 ms |
35652 KB |
Output is correct |
66 |
Correct |
301 ms |
38732 KB |
Output is correct |
67 |
Correct |
6 ms |
1204 KB |
Output is correct |
68 |
Correct |
4 ms |
852 KB |
Output is correct |
69 |
Correct |
440 ms |
73428 KB |
Output is correct |
70 |
Correct |
583 ms |
80380 KB |
Output is correct |
71 |
Correct |
737 ms |
88184 KB |
Output is correct |
72 |
Correct |
655 ms |
72732 KB |
Output is correct |
73 |
Correct |
753 ms |
85040 KB |
Output is correct |
74 |
Correct |
553 ms |
65292 KB |
Output is correct |
75 |
Correct |
580 ms |
77896 KB |
Output is correct |