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>
#include <algorithm>
using namespace std;
int N,H[100100],T[100100],S;
struct p{
p(){
a = b = i = 0;
}
p(double a_, long long b_, int i_){
a = a_; b = b_; i = i_;
}
double a; long long b; int i;
bool operator <(const p t) const{
return a * t.b > b * t.a;
}
}P[100100];
bool go(double m)
{
for (int i=0;i<N;i++){
P[i] = p(m+T[i]*H[i],T[i],i+1);
}
sort(P,P+N);
return p(P[0].a*P[1].b+P[1].a*P[0].b,P[0].b*P[1].b,0) < p(S,1,0);
}
int main()
{
scanf ("%d",&N);
for (int i=0;i<N;i++){
scanf ("%d",&H[i]); S += H[i];
}
for (int j=0;j<N;j++) scanf ("%d",&T[j]);
double l = 0, r = 1e9, m;
for (int i=0;i<70;i++){
m = (l + r) / 2;
if (go(m)) r = m;
else l = m;
}
go(l);
int a = P[0].i, b = P[1].i;
if (a > b) swap(a,b);
printf ("%d %d\n",a,b);
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... |