This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
int n,ai=1,aj=2;
long long h[100010],t[100010],H;
int chk(double m){
int i,mi,mj;
double s,m1=0,m2=0;
for(i=1;i<=n;++i){
s=h[i]+m/t[i];
if(m1<s)m2=m1,mj=mi,m1=s,mi=i;
else if(m2<s)m2=s,mj=i;
}
if(m1+m2>H)ai=mi,aj=mj;
return m1+m2>H;
}
double f(){
double x=H-h[ai]-h[aj],y=1.0/t[ai]+1.0/t[aj];
return x/y;
}
int main(){
int i;
scanf("%d",&n);
for(i=1;i<=n;++i)scanf("%lld",h+i),H+=h[i];
for(i=1;i<=n;++i)scanf("%lld",t+i);
double l=0,r=1e8,m;
while((r-l)/r>1e-10){
m=(l+r)/2;
if(chk(m))r=f();
else l=m;
}
if(ai>aj)ai^=aj^=ai^=aj;
printf("%d %d",ai,aj);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |