#include<bits/stdc++.h>
#include "tickets.h"
using namespace std;
struct Node
{
int x;
int i,j;
bool operator <(const Node &B)const
{
if(x==B.x)
{
if(i==B.i){return j<B.j;}
else{return i<B.i;}
}
else{return x<B.x;}
}
};
int k,n,m,n2;
vector<vector<int>>answer;
vector<vector<Node>>Tab;
vector<Node>Lista;
vector<int>V1[1509],V2[1509];
int CzyZajal[1509];
bool CzyMozna(Node x)
{
int s1=0,s2=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(Tab[i][j]<x){s1++;}
else{s2++;}
}
}
return s1>=s2;
}
Node BinSearch()
{
int l=0;
int p=(int)Lista.size()-1;
while(l<p)
{
const int mid=(l+p)>>1;
if(CzyMozna(Lista[mid])){p=mid;}
else{l=mid+1;}
}
return Lista[l];
}
long long find_maximum(int K, vector<vector<int>>A)
{
k=K;
n = A.size();
n2=n/2;
m = A[0].size();
answer.resize(n,vector<int>(m,-1));
for(int i=0;i<n;i++)
{
vector<Node>Temp;
for(int j=0;j<m;j++)
{
Temp.push_back({A[i][j],i,j});
Lista.push_back({A[i][j],i,j});
}
sort(Temp.begin(),Temp.end());
Tab.push_back(Temp);
}
sort(Lista.begin(),Lista.end());
Node xd=Lista[(int)Lista.size()/2];
long long wynik=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(Tab[i][j]<xd)
{
wynik-=Tab[i][j].x;
V1[i].push_back(Tab[i][j].j);
}
else
{
wynik+=Tab[i][j].x;
V2[i].push_back(Tab[i][j].j);
}
}
}
memset(CzyZajal,-1,sizeof(CzyZajal));
for(int i=0;i<k;i++)
{
int ile=0;
for(int j=0;j<n;j++)
{
if(ile==n2){break;}
if((int)V1[j].size()>0)
{
int u=V1[j].back();
V1[j].pop_back();
CzyZajal[j]=i;
answer[j][u]=i;
ile++;
}
}
for(int j=0;j<n;j++)
{
if(CzyZajal[j]!=i&&(int)V2[j].size()>0)
{
int u=V2[j].back();
V2[j].pop_back();
answer[j][u]=i;
}
}
}
allocate_tickets(answer);
return wynik;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Contestant returned 803235448 but the tickets gives a total value of 1095508474 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
There is no ticket of color 3 on day 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
There is no ticket of color 8 on day 5 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
2 ms |
860 KB |
Contestant returned 19938459097 but the tickets gives a total value of 1593618503176 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
2 ms |
860 KB |
Contestant returned 19938459097 but the tickets gives a total value of 1593618503176 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
860 KB |
Output is correct |
7 |
Incorrect |
0 ms |
344 KB |
Contestant returned 803235448 but the tickets gives a total value of 1095508474 |
8 |
Halted |
0 ms |
0 KB |
- |