#include<stdio.h>
int n, da, db;
long long sum, hi[100100], ti[100100];
double mi=0, mx, md;
double pick(int a, int b){
double honey=sum-hi[a]-hi[b];
double til=(1.0/ti[a])+(1.0/ti[b]);
return honey/til;
}
bool test(double vl){
double ma=0, mb=0;
int i, ia, ib;
for(i=0; i<n; i++){
double gp=hi[i]+vl/ti[i];
if(ma<gp)mb=ma, ib=ia, ma=gp, ia=i;
else if(mb<gp)mb=gp, ib=i;
}
if(ma+mb > sum)da=ia, db=ib;
return (ma+mb) > sum;
}
int main(){
int i;
scanf("%d", &n);
for(i=0; i<n; i++)scanf("%lld", &hi[i]), sum+=hi[i];
for(i=0; i<n; i++)scanf("%lld", &ti[i]);
da=0, db=1, mx=pick(0,1);
while((mx-mi)/mx > 1e-10){
md=(mi+mx)/2.0;
if(test(md))mx=pick(da,db);
else mi=md;
}
if(da>db){
int im=da;
da=db, db=im;
}
printf("%d %d", da+1, db+1);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2648 KB |
Output is correct |
2 |
Correct |
0 ms |
2648 KB |
Output is correct |
3 |
Correct |
0 ms |
2648 KB |
Output is correct |
4 |
Correct |
0 ms |
2648 KB |
Output is correct |
5 |
Correct |
0 ms |
2648 KB |
Output is correct |
6 |
Correct |
0 ms |
2648 KB |
Output is correct |
7 |
Correct |
0 ms |
2648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2648 KB |
Output is correct |
2 |
Correct |
0 ms |
2648 KB |
Output is correct |
3 |
Correct |
0 ms |
2648 KB |
Output is correct |
4 |
Correct |
0 ms |
2648 KB |
Output is correct |
5 |
Correct |
0 ms |
2648 KB |
Output is correct |
6 |
Correct |
0 ms |
2648 KB |
Output is correct |
7 |
Correct |
0 ms |
2648 KB |
Output is correct |
8 |
Correct |
0 ms |
2648 KB |
Output is correct |
9 |
Correct |
0 ms |
2648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
68 ms |
2648 KB |
Output is correct |
2 |
Correct |
39 ms |
2648 KB |
Output is correct |
3 |
Correct |
55 ms |
2648 KB |
Output is correct |
4 |
Correct |
65 ms |
2648 KB |
Output is correct |
5 |
Correct |
33 ms |
2648 KB |
Output is correct |
6 |
Correct |
23 ms |
2648 KB |
Output is correct |
7 |
Correct |
33 ms |
2648 KB |
Output is correct |
8 |
Correct |
66 ms |
2648 KB |
Output is correct |
9 |
Correct |
60 ms |
2648 KB |
Output is correct |
10 |
Correct |
60 ms |
2648 KB |
Output is correct |
11 |
Correct |
55 ms |
2648 KB |
Output is correct |
12 |
Correct |
39 ms |
2648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
2648 KB |
Output is correct |
2 |
Correct |
52 ms |
2648 KB |
Output is correct |
3 |
Correct |
64 ms |
2648 KB |
Output is correct |
4 |
Correct |
56 ms |
2648 KB |
Output is correct |
5 |
Correct |
36 ms |
2648 KB |
Output is correct |
6 |
Correct |
70 ms |
2648 KB |
Output is correct |
7 |
Correct |
69 ms |
2648 KB |
Output is correct |
8 |
Correct |
66 ms |
2648 KB |
Output is correct |
9 |
Correct |
71 ms |
2648 KB |
Output is correct |
10 |
Correct |
22 ms |
2648 KB |
Output is correct |
11 |
Correct |
60 ms |
2648 KB |
Output is correct |
12 |
Correct |
60 ms |
2648 KB |
Output is correct |
13 |
Correct |
61 ms |
2648 KB |
Output is correct |
14 |
Correct |
71 ms |
2648 KB |
Output is correct |
15 |
Correct |
57 ms |
2648 KB |
Output is correct |
16 |
Correct |
63 ms |
2648 KB |
Output is correct |
17 |
Correct |
39 ms |
2648 KB |
Output is correct |