#include "tickets.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 15e2;
vector<pair<int,int>> nr;
vector <int> bad;
int r[N];
int l[N];
bool vis[N];
long long find_maximum(int k, std::vector<std::vector<int>> x) {
int n = x.size();
int m = x[0].size();
std::vector<std::vector<int>> answer;
answer.resize(n);
ll score = 0;
for(int i = 0;i < n;i++){
answer[i].resize(m);
for(int j = 0;j < k;j++){
nr.push_back({- x[i][j] - x[i][m - k + j], i});
score-=x[i][j];
}
for(int j = 0;j < m;j++){
answer[i][j] = -1;
}
l[i] = k;
}
sort(nr.begin(),nr.end());
for(int i = 0;i < n*k/2;i++){
score+=x[nr[i].second][k - 1 - r[nr[i].second]];
score+=x[nr[i].second][m - 1 - r[nr[i].second]];
r[nr[i].second]++;
l[nr[i].second]--;
}
for(int i = 0;i < k;i++){
int cnt1 = 0,cnt2 = 0;
for(int j = 0;j < n;j++){
vis[j] = 1;
if(r[j] == 0){
///take left
answer[j][l[j] - 1] = i;
cnt2++;
l[j]--;
}else if(l[j] == 0){
///take right
answer[j][m - r[j]] = i;
cnt1++;
r[j]--;
}else vis[j] = 0;
}
for(int j = 0;j < n;j++){
if(!vis[j]){
vis[j] = 1;
if(cnt1 != n/2){
///take right
answer[j][m - r[j]] = i;
cnt1++;
r[j]--;
}else{
///take left
answer[j][l[j] - 1] = i;
cnt2++;
l[j]--;
}
}
}
}
allocate_tickets(answer);
return score;
}
/**
1, [[5, 9], [1, 4], [3, 6], [2, 7]]
4 2 1
5 9
1 4
3 6
2 7
**/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
2 ms |
516 KB |
Output is correct |
5 |
Correct |
14 ms |
3216 KB |
Output is correct |
6 |
Correct |
346 ms |
73288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
2 ms |
592 KB |
Output is correct |
5 |
Correct |
16 ms |
2892 KB |
Output is correct |
6 |
Correct |
385 ms |
67160 KB |
Output is correct |
7 |
Correct |
354 ms |
69600 KB |
Output is correct |
8 |
Correct |
2 ms |
592 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
4 ms |
1120 KB |
Output is correct |
13 |
Correct |
12 ms |
2604 KB |
Output is correct |
14 |
Correct |
12 ms |
2588 KB |
Output is correct |
15 |
Correct |
383 ms |
72184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
592 KB |
Output is correct |
5 |
Correct |
21 ms |
3964 KB |
Output is correct |
6 |
Correct |
4 ms |
848 KB |
Output is correct |
7 |
Correct |
4 ms |
1104 KB |
Output is correct |
8 |
Correct |
515 ms |
94432 KB |
Output is correct |
9 |
Correct |
487 ms |
89560 KB |
Output is correct |
10 |
Correct |
491 ms |
89560 KB |
Output is correct |
11 |
Correct |
539 ms |
94680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
2 ms |
592 KB |
Output is correct |
3 |
Correct |
2 ms |
516 KB |
Output is correct |
4 |
Correct |
2 ms |
592 KB |
Output is correct |
5 |
Correct |
3 ms |
592 KB |
Output is correct |
6 |
Correct |
2 ms |
592 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
496 KB |
Output is correct |
9 |
Correct |
2 ms |
592 KB |
Output is correct |
10 |
Correct |
2 ms |
592 KB |
Output is correct |
11 |
Correct |
2 ms |
592 KB |
Output is correct |
12 |
Correct |
2 ms |
592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
2 ms |
592 KB |
Output is correct |
3 |
Correct |
2 ms |
516 KB |
Output is correct |
4 |
Correct |
2 ms |
592 KB |
Output is correct |
5 |
Correct |
3 ms |
592 KB |
Output is correct |
6 |
Correct |
2 ms |
592 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
496 KB |
Output is correct |
9 |
Correct |
2 ms |
592 KB |
Output is correct |
10 |
Correct |
2 ms |
592 KB |
Output is correct |
11 |
Correct |
2 ms |
592 KB |
Output is correct |
12 |
Correct |
2 ms |
592 KB |
Output is correct |
13 |
Correct |
16 ms |
3408 KB |
Output is correct |
14 |
Correct |
14 ms |
3408 KB |
Output is correct |
15 |
Correct |
30 ms |
3660 KB |
Output is correct |
16 |
Correct |
22 ms |
4104 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
2 ms |
592 KB |
Output is correct |
19 |
Correct |
2 ms |
592 KB |
Output is correct |
20 |
Correct |
19 ms |
3284 KB |
Output is correct |
21 |
Correct |
21 ms |
3784 KB |
Output is correct |
22 |
Correct |
21 ms |
3268 KB |
Output is correct |
23 |
Correct |
22 ms |
3780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
848 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
2 ms |
516 KB |
Output is correct |
11 |
Correct |
14 ms |
3216 KB |
Output is correct |
12 |
Correct |
346 ms |
73288 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
2 ms |
592 KB |
Output is correct |
17 |
Correct |
16 ms |
2892 KB |
Output is correct |
18 |
Correct |
385 ms |
67160 KB |
Output is correct |
19 |
Correct |
354 ms |
69600 KB |
Output is correct |
20 |
Correct |
2 ms |
592 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
4 ms |
1120 KB |
Output is correct |
25 |
Correct |
12 ms |
2604 KB |
Output is correct |
26 |
Correct |
12 ms |
2588 KB |
Output is correct |
27 |
Correct |
383 ms |
72184 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
504 KB |
Output is correct |
31 |
Correct |
2 ms |
592 KB |
Output is correct |
32 |
Correct |
21 ms |
3964 KB |
Output is correct |
33 |
Correct |
4 ms |
848 KB |
Output is correct |
34 |
Correct |
4 ms |
1104 KB |
Output is correct |
35 |
Correct |
515 ms |
94432 KB |
Output is correct |
36 |
Correct |
487 ms |
89560 KB |
Output is correct |
37 |
Correct |
491 ms |
89560 KB |
Output is correct |
38 |
Correct |
539 ms |
94680 KB |
Output is correct |
39 |
Correct |
1 ms |
336 KB |
Output is correct |
40 |
Correct |
2 ms |
592 KB |
Output is correct |
41 |
Correct |
2 ms |
516 KB |
Output is correct |
42 |
Correct |
2 ms |
592 KB |
Output is correct |
43 |
Correct |
3 ms |
592 KB |
Output is correct |
44 |
Correct |
2 ms |
592 KB |
Output is correct |
45 |
Correct |
1 ms |
336 KB |
Output is correct |
46 |
Correct |
1 ms |
496 KB |
Output is correct |
47 |
Correct |
2 ms |
592 KB |
Output is correct |
48 |
Correct |
2 ms |
592 KB |
Output is correct |
49 |
Correct |
2 ms |
592 KB |
Output is correct |
50 |
Correct |
2 ms |
592 KB |
Output is correct |
51 |
Correct |
16 ms |
3408 KB |
Output is correct |
52 |
Correct |
14 ms |
3408 KB |
Output is correct |
53 |
Correct |
30 ms |
3660 KB |
Output is correct |
54 |
Correct |
22 ms |
4104 KB |
Output is correct |
55 |
Correct |
1 ms |
336 KB |
Output is correct |
56 |
Correct |
2 ms |
592 KB |
Output is correct |
57 |
Correct |
2 ms |
592 KB |
Output is correct |
58 |
Correct |
19 ms |
3284 KB |
Output is correct |
59 |
Correct |
21 ms |
3784 KB |
Output is correct |
60 |
Correct |
21 ms |
3268 KB |
Output is correct |
61 |
Correct |
22 ms |
3780 KB |
Output is correct |
62 |
Correct |
41 ms |
8472 KB |
Output is correct |
63 |
Correct |
44 ms |
8556 KB |
Output is correct |
64 |
Correct |
56 ms |
10720 KB |
Output is correct |
65 |
Correct |
193 ms |
37296 KB |
Output is correct |
66 |
Correct |
234 ms |
41748 KB |
Output is correct |
67 |
Correct |
5 ms |
1104 KB |
Output is correct |
68 |
Correct |
4 ms |
848 KB |
Output is correct |
69 |
Correct |
349 ms |
73260 KB |
Output is correct |
70 |
Correct |
454 ms |
84524 KB |
Output is correct |
71 |
Correct |
573 ms |
94572 KB |
Output is correct |
72 |
Correct |
456 ms |
79188 KB |
Output is correct |
73 |
Correct |
493 ms |
89832 KB |
Output is correct |
74 |
Correct |
372 ms |
69416 KB |
Output is correct |
75 |
Correct |
426 ms |
82204 KB |
Output is correct |