#include "squad.h"
#include <bits/stdc++.h>
using namespace std;
struct Point{
long long x, y;
int ind;
bool operator <(const Point A) const{
if(x==A.x) return y<A.y;
return x<A.x;
}
};
vector<Point> pa, pb;
int n;
vector<Point> f(vector<Point> in){
vector<Point> ret;
for(auto i:in){
while(!ret.empty()&&ret[ret.size()-1].y<=i.y) ret.pop_back();
ret.push_back(i);
}
return ret;
}
void Init(std::vector<int> A, std::vector<int> D, std::vector<int> P){
n = A.size();
for(int i=0;i<n;i++){
pa.push_back({A[i],P[i],i});
pb.push_back({D[i],P[i],i});
}
sort(pa.begin(), pa.end());
sort(pb.begin(), pb.end());
pa = f(pa);
pb = f(pb);
/*
cout<<"pa --------------\n";
for(auto i:pa){
cout<<i.x<<" "<<i.y<<" "<<i.ind<<"\n";
}
cout<<"pb --------------\n";
for(auto i:pb){
cout<<i.x<<" "<<i.y<<" "<<i.ind<<"\n";
}
cout<<"end of debug-----\n";
*/
}
long long BestSquad(int X, int Y){
int l=0,r=n-2,inda=0,indb=0;
while(l<r){
int mid = (l+r)/2;
if((pa[mid].y-pa[mid+1].y)*Y<(pa[mid+1].x-pa[mid].x)*X)
{
inda=max(inda,mid+1);
l=mid+1;
}
else r=mid-1;
}
l=0;r=n-2;
while(l<r){
int mid = (l+r)/2;
if((pb[mid].y-pb[mid+1].y)*Y<(pb[mid+1].x-pb[mid].x)*X)
{
indb=max(indb,mid+1);
l=mid+1;
}
else r=mid-1;
}
//cout<<"inda : "<<inda<<" indb : "<<indb<<endl;
long long ret=0;
for(int i=-1;i<=1;i++){
for(int j=-1;j<=1;j++){
int aa=inda+i, bb=indb+j;
if(0<=aa&&aa<pa.size()&&0<=bb&&bb<pb.size()&&pa[aa].ind!=pb[bb].ind){
long long t = (pa[aa].x+pb[bb].x)*X+(pa[aa].y+pb[bb].y)*Y;
//cout<<"check "<<aa<<" "<<bb<<" "<<t<<"\n";
if(ret<t) ret=t;
}
}
}
return ret;
}
Compilation message
squad.cpp: In function 'long long int BestSquad(int, int)':
squad.cpp:73:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(0<=aa&&aa<pa.size()&&0<=bb&&bb<pb.size()&&pa[aa].ind!=pb[bb].ind){
~~^~~~~~~~~~
squad.cpp:73:37: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(0<=aa&&aa<pa.size()&&0<=bb&&bb<pb.size()&&pa[aa].ind!=pb[bb].ind){
~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Incorrect |
6 ms |
512 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Incorrect |
6 ms |
512 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |