#include "tickets.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define ll long long
#define pb push_back
#define eb emplace_back
#define p32 pair<int,int>
long long find_maximum(int k, std::vector<std::vector<int>> x) {
int n = x.size(), m = x[0].size();
vector<vi> ans;
if(m==1){
vi p;
for(int i = 0; i<n; i++){ ans.pb({0}); p.pb(x[i][0]);}
sort(p.begin(),p.end());
ll sum = 0;
for(int i =0; i<n; i++) sum+=abs(p[n/2]-p[i]);
allocate_tickets(ans);
return sum;
}
ll result = 0;
bool finalchoice[n];
for(int i = 0; i<2*n; i++){
bool choice[n]; memset(choice,0,sizeof choice); //true if we pick the big card
int mid = x[i%n][0];
if(i>=n){ mid = x[i%n][m-1]; choice[i] = true;}
int lowcnt = 0,highcnt = 0;
ll sum = 0;
priority_queue<p32,vector<p32>,greater<>> q;
for(int j = 0; j<n; j++){
if(i==j) continue;
int a = x[j][0], b = x[j][m-1];
if(a>mid){
sum+=b-mid;
highcnt++;
choice[j] = true;
}
else if(b<mid){
sum+=mid-a;
lowcnt++;
}
else if(mid-a>b-mid){
sum+=mid-a;
lowcnt++;
q.emplace(2*mid-a-b,j);
}
else{
sum+=b-mid;
highcnt++;
choice[j] = true;
q.emplace(a+b-2*mid,j);
}
}
while(highcnt-lowcnt>1&&!q.empty()) {
int x = q.top().first, j = q.top().second;
if(choice[j]){
sum-=x;
highcnt--;
lowcnt++;
}
q.pop();
}
while(lowcnt-highcnt>1&&!q.empty()){
int x = q.top().first, j = q.top().second;
if(!choice[j]){
sum-=x;
highcnt++;
lowcnt--;
}
q.pop();
}
if(abs(highcnt-lowcnt)>1) continue;
if(sum>result){
for(int j = 0; j<n; j++) finalchoice[j] = choice[j];
result = sum;
}
}
ans.resize(n);
fill(ans.begin(),ans.end(),vi(m,-1));
for(int i = 0; i<n; i++){
if(finalchoice[i]) ans[i][m-1] = 0;
else ans[i][0] = 0;
}
allocate_tickets(ans);
return result;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
344 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 |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Contestant returned 1413427872 but the tickets gives a total value of 2727881086 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
There is no ticket of color 0 on day 1 |
2 |
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 1 |
2 |
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 1 |
2 |
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 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
860 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Incorrect |
0 ms |
348 KB |
Contestant returned 1413427872 but the tickets gives a total value of 2727881086 |
9 |
Halted |
0 ms |
0 KB |
- |