#include "tickets.h"
#include <bits/stdc++.h>
using namespace std;
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));
int timer = 0;
int sum = 0;
vector<int> l(n, 0), r(n, 0), rr(n, 0);
for(int i = 0; i < n; i ++) {
l[i] = 0;
r[i] = m - 1 - k + 1;
timer += k;
for(int j = 0; j < k; j ++)
sum += x[i][m - 1 - j];
}
for(int i = 0; i < n; i ++) rr[i] = m - 1;
priority_queue<array<int, 2>> pq;
for(int i = 0; i < n; i ++) {
int L = l[i];
int R = r[i];
pq.push({- x[i][L] - x[i][R], i});
}
while(!pq.empty() && timer > k * n / 2) {
int c = pq.top()[0];
int i = pq.top()[1];
pq.pop();
sum += c;
l[i] ++ ;
r[i] ++ ;
timer --;
if(r[i] < m) {
int L = l[i];
int R = r[i];
pq.push({- x[i][L] - x[i][R], i});
}
}
for(int j = 0; j < k; j ++) {
vector<array<int, 3>> p;
for(int i = 0; i < n; i ++) {
if(l[i] > 0) p.push_back({x[i][l[i] - 1], i, 0});
if(rr[i] >= r[i]) p.push_back({x[i][rr[i]], i, 1});
}
sort(p.begin(), p.end());
reverse(p.begin(), p.end());
vector<int> mark(n, 0);
int cnt = 0, _cnt = 0;
for(auto [c, i, type] : p) {
if(mark[i]) continue ;
if(type == 0 && cnt < n / 2) {
cnt ++ ;
mark[i] = true;
answer[i][l[i] - 1] = j;
l[i] -- ;
}
if(type == 1 && _cnt < n / 2) {
_cnt ++ ;
mark[i] = true;
answer[i][rr[i]] = j;
rr[i] ++ ;
}
}
}
allocate_tickets(answer);
return sum;
}
Compilation message
tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:67:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
67 | for(auto [c, i, type] : p) {
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
436 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Contestant returned 18919508441 but the tickets gives a total value of 1739639257 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Contestant returned 2727881086 but the tickets gives a total value of -1567086210 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
There is no ticket of color 0 on day 2 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
436 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Contestant returned 18919508441 but the tickets gives a total value of 1739639257 |
5 |
Halted |
0 ms |
0 KB |
- |