#include "tickets.h"
#include <bits/stdc++.h>
using namespace std;
long long find_maximum(int k, std::vector<std::vector<int>> x) {
int n = x.size();
int m = x[0].size();
int i, j;
vector<vector<int>>answer = x;
for(i=0;i<n;i++)
for(j=0;j<m;j++)
answer[i][j] = -1;
long long wynik = 0;
priority_queue<pair<long long, pair<int, int>>>kolejka;
vector<set<int>>dodatnie(n), ujemne(n);
for(i=0;i<n;i++){
for(j=m-k;j<m;j++){
wynik+=x[i][j];
dodatnie[i].insert(j);
}
kolejka.push({-(long long)x[i][m-k]-x[i][0], {i, 0}});
}
// int dl = m-k;
for(int minus=0;minus<k*n/2;minus++){
i = kolejka.top().second.first;
j = kolejka.top().second.second;
wynik+=kolejka.top().first;
kolejka.pop();
ujemne[i].insert(j);
dodatnie[i].erase(j+m-k);
j++;
if(j<k)
kolejka.push({-(long long)x[i][m-k+j]-x[i][j], {i,j}});
}
// exit(0);
//0011111
//1111100
int bilans = 0;
for(i=0;i<k;i++){
for(j=0;j<n;j++){
if(dodatnie[j].size()>ujemne[j].size() || (dodatnie[j].size()==ujemne[j].size() && bilans>=0)){
auto it = *dodatnie[j].begin();
answer[j][it] = i;
bilans++;
dodatnie[j].erase(it);
}
else{
auto it = *ujemne[j].begin();
answer[j][it] = i;
bilans--;
ujemne[j].erase(it);
}
}
}
allocate_tickets(answer);
return wynik;
}
# |
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 |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
14 ms |
3216 KB |
Output is correct |
6 |
Correct |
348 ms |
73404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Contestant returned 2 but the tickets gives a total value of 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Contestant returned 11 but the tickets gives a total value of 13 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Contestant returned 11 but the tickets gives a total value of 13 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Contestant returned 11 but the tickets gives a total value of 13 |
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 |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
860 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
14 ms |
3216 KB |
Output is correct |
12 |
Correct |
348 ms |
73404 KB |
Output is correct |
13 |
Incorrect |
0 ms |
344 KB |
Contestant returned 2 but the tickets gives a total value of 6 |
14 |
Halted |
0 ms |
0 KB |
- |