#include "tickets.h"
#include <bits/stdc++.h>
using namespace std;
/*
void allocate_tickets(vector<vector<int>> arr) {
for(auto v : arr) {
for(auto n : v) {
cout << n << " ";
}
cout << "\n";
}
cout << endl;
}
*/
long long find_maximum(int K, vector<vector<int>> arr) {
int N = arr.size();
int M = arr[0].size();
int G = M - K;
long long ans = 0;
vector<vector<int>> ret;
vector<vector<int>> typ;
ret.resize(N);
typ.resize(N);
priority_queue<pair<int, pair<int, int>>> pq;
for(int i = 0; i < N; i++) {
ret[i].resize(M, -1);
typ[i].resize(M);
for(int j = M - 1; j >= M - K; j--) {
ans += arr[i][j];
pq.push(make_pair(-arr[i][j] - arr[i][j-G], make_pair(i, j)));
typ[i][j] = 1;
}
}
int tot = N * K / 2;
while(tot--) {
auto p = pq.top();
ans += p.first;
typ[p.second.first][p.second.second] = 0;
typ[p.second.first][p.second.second-G] = -1;
pq.pop();
}
vector<pair<int, int>> cnt(N);
vector<int> tkn(N);
for(int i = 0; i < N; i++) {
int c = 0;
for(int j = 0; j < M; j++) {
if(typ[i][j] == 1) {
c++;
}
}
cnt[i] = make_pair(c, i);
}
for(int k = 0; k < K; k++) {
sort(cnt.begin(), cnt.end());
for(int n = 0; n < N / 2; n++) {
auto p = cnt[n];
ret[p.second][k - tkn[p.second]] = k;
}
for(int n = N/2; n < N; n++) {
pair<int,int>& p = cnt[n];
//cout << p.second << " " << M-1-tkn[p.second] << endl;
ret[p.second][M-1-tkn[p.second]] = k;
tkn[p.second]++;
p.first--;
}
}
allocate_tickets(ret);
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
1 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 |
2 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
19 ms |
3612 KB |
Output is correct |
6 |
Correct |
521 ms |
66644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
20 ms |
3084 KB |
Output is correct |
6 |
Correct |
555 ms |
68136 KB |
Output is correct |
7 |
Correct |
569 ms |
72592 KB |
Output is correct |
8 |
Correct |
3 ms |
724 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
6 ms |
1076 KB |
Output is correct |
13 |
Correct |
21 ms |
2776 KB |
Output is correct |
14 |
Correct |
19 ms |
2828 KB |
Output is correct |
15 |
Correct |
575 ms |
76100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
244 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
596 KB |
Output is correct |
5 |
Correct |
31 ms |
4324 KB |
Output is correct |
6 |
Correct |
5 ms |
976 KB |
Output is correct |
7 |
Correct |
6 ms |
1236 KB |
Output is correct |
8 |
Correct |
892 ms |
86908 KB |
Output is correct |
9 |
Correct |
888 ms |
82636 KB |
Output is correct |
10 |
Correct |
785 ms |
82864 KB |
Output is correct |
11 |
Correct |
856 ms |
87300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
3 ms |
468 KB |
Output is correct |
6 |
Correct |
3 ms |
568 KB |
Output is correct |
7 |
Correct |
2 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 |
4 ms |
500 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
3 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
3 ms |
468 KB |
Output is correct |
6 |
Correct |
3 ms |
568 KB |
Output is correct |
7 |
Correct |
2 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 |
4 ms |
500 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
3 ms |
596 KB |
Output is correct |
13 |
Correct |
19 ms |
3504 KB |
Output is correct |
14 |
Correct |
20 ms |
3604 KB |
Output is correct |
15 |
Correct |
25 ms |
3824 KB |
Output is correct |
16 |
Correct |
31 ms |
4360 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
492 KB |
Output is correct |
19 |
Correct |
2 ms |
464 KB |
Output is correct |
20 |
Correct |
25 ms |
3380 KB |
Output is correct |
21 |
Correct |
26 ms |
3872 KB |
Output is correct |
22 |
Correct |
28 ms |
3700 KB |
Output is correct |
23 |
Correct |
31 ms |
4152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
1 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 |
2 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
300 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
19 ms |
3612 KB |
Output is correct |
12 |
Correct |
521 ms |
66644 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 |
20 ms |
3084 KB |
Output is correct |
18 |
Correct |
555 ms |
68136 KB |
Output is correct |
19 |
Correct |
569 ms |
72592 KB |
Output is correct |
20 |
Correct |
3 ms |
724 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
6 ms |
1076 KB |
Output is correct |
25 |
Correct |
21 ms |
2776 KB |
Output is correct |
26 |
Correct |
19 ms |
2828 KB |
Output is correct |
27 |
Correct |
575 ms |
76100 KB |
Output is correct |
28 |
Correct |
1 ms |
244 KB |
Output is correct |
29 |
Correct |
1 ms |
300 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
2 ms |
596 KB |
Output is correct |
32 |
Correct |
31 ms |
4324 KB |
Output is correct |
33 |
Correct |
5 ms |
976 KB |
Output is correct |
34 |
Correct |
6 ms |
1236 KB |
Output is correct |
35 |
Correct |
892 ms |
86908 KB |
Output is correct |
36 |
Correct |
888 ms |
82636 KB |
Output is correct |
37 |
Correct |
785 ms |
82864 KB |
Output is correct |
38 |
Correct |
856 ms |
87300 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
2 ms |
468 KB |
Output is correct |
41 |
Correct |
2 ms |
468 KB |
Output is correct |
42 |
Correct |
2 ms |
468 KB |
Output is correct |
43 |
Correct |
3 ms |
468 KB |
Output is correct |
44 |
Correct |
3 ms |
568 KB |
Output is correct |
45 |
Correct |
2 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 |
4 ms |
500 KB |
Output is correct |
49 |
Correct |
2 ms |
468 KB |
Output is correct |
50 |
Correct |
3 ms |
596 KB |
Output is correct |
51 |
Correct |
19 ms |
3504 KB |
Output is correct |
52 |
Correct |
20 ms |
3604 KB |
Output is correct |
53 |
Correct |
25 ms |
3824 KB |
Output is correct |
54 |
Correct |
31 ms |
4360 KB |
Output is correct |
55 |
Correct |
1 ms |
340 KB |
Output is correct |
56 |
Correct |
2 ms |
492 KB |
Output is correct |
57 |
Correct |
2 ms |
464 KB |
Output is correct |
58 |
Correct |
25 ms |
3380 KB |
Output is correct |
59 |
Correct |
26 ms |
3872 KB |
Output is correct |
60 |
Correct |
28 ms |
3700 KB |
Output is correct |
61 |
Correct |
31 ms |
4152 KB |
Output is correct |
62 |
Correct |
58 ms |
8684 KB |
Output is correct |
63 |
Correct |
73 ms |
8716 KB |
Output is correct |
64 |
Correct |
94 ms |
10872 KB |
Output is correct |
65 |
Correct |
305 ms |
32220 KB |
Output is correct |
66 |
Correct |
395 ms |
38044 KB |
Output is correct |
67 |
Correct |
7 ms |
1236 KB |
Output is correct |
68 |
Correct |
8 ms |
976 KB |
Output is correct |
69 |
Correct |
615 ms |
65224 KB |
Output is correct |
70 |
Correct |
815 ms |
71616 KB |
Output is correct |
71 |
Correct |
895 ms |
88900 KB |
Output is correct |
72 |
Correct |
782 ms |
85868 KB |
Output is correct |
73 |
Correct |
856 ms |
78148 KB |
Output is correct |
74 |
Correct |
615 ms |
67864 KB |
Output is correct |
75 |
Correct |
721 ms |
67156 KB |
Output is correct |