CF639E.Bear and Paradox

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Limak is a big polar bear. He prepared nn problems for an algorithmic contest. The ii -th problem has initial score pip_{i} . Also, testers said that it takes tit_{i} minutes to solve the ii -th problem. Problems aren't necessarily sorted by difficulty and maybe harder problems have smaller initial score but it's too late to change it — Limak has already announced initial scores for problems. Though it's still possible to adjust the speed of losing points, denoted by cc in this statement.

Let TT denote the total number of minutes needed to solve all problems (so, T=t1+t2+...+tnT=t_{1}+t_{2}+...+t_{n} ). The contest will last exactly TT minutes. So it's just enough to solve all problems.

Points given for solving a problem decrease linearly. Solving the ii -th problem after xx minutes gives exactly points, where is some real constant that Limak must choose.

Let's assume that cc is fixed. During a contest a participant chooses some order in which he or she solves problems. There are n!n! possible orders and each of them gives some total number of points, not necessarily integer. We say that an order is optimal if it gives the maximum number of points. In other words, the total number of points given by this order is greater or equal than the number of points given by any other order. It's obvious that there is at least one optimal order. However, there may be more than one optimal order.

Limak assumes that every participant will properly estimate tit_{i} at the very beginning and will choose some optimal order. He also assumes that testers correctly predicted time needed to solve each problem.

For two distinct problems ii and jj such that p_{i}<p_{j} Limak wouldn't be happy to see a participant with strictly more points for problem ii than for problem jj . He calls such a situation a paradox.

It's not hard to prove that there will be no paradox for c=0c=0 . The situation may be worse for bigger cc . What is the maximum real value cc (remember that ) for which there is no paradox possible, that is, there will be no paradox for any optimal order of solving problems?

It can be proved that the answer (the maximum cc as described) always exists.

输入格式

The first line contains one integer nn ( 2<=n<=1500002<=n<=150000 ) — the number of problems.

The second line contains nn integers p1,p2,...,pnp_{1},p_{2},...,p_{n} ( 1<=pi<=1081<=p_{i}<=10^{8} ) — initial scores.

The third line contains nn integers t1,t2,...,tnt_{1},t_{2},...,t_{n} ( 1<=ti<=1081<=t_{i}<=10^{8} ) where tit_{i} is the number of minutes needed to solve the ii -th problem.

输出格式

Print one real value on a single line — the maximum value of cc that and there is no optimal order with a paradox. Your answer will be considered correct if its absolute or relative error does not exceed 10610^{-6} .

Namely: let's assume that your answer is aa , and the answer of the jury is bb . The checker program will consider your answer correct if .

输入输出样例

  • 输入#1

    3
    4 3 10
    1 1 8
    

    输出#1

    0.62500000000
    
  • 输入#2

    4
    7 20 15 10
    7 20 15 10
    

    输出#2

    0.31901840491
    
  • 输入#3

    2
    10 20
    10 1
    

    输出#3

    1.00000000000
    

说明/提示

In the first sample, there are 33 problems. The first is (4,1)(4,1) (initial score is 44 and required time is 11 minute), the second problem is (3,1)(3,1) and the third one is (10,8)(10,8) . The total time is T=1+1+8=10T=1+1+8=10 .

Let's show that there is a paradox for c=0.7c=0.7 . Solving problems in order 11 , 22 , 33 turns out to give the best total score, equal to the sum of:

  1. solved 11 minute after the start:
  2. solved 22 minutes after the start:
  3. solved 1010 minutes after the start:

So, this order gives 3.72+2.58+3=9.33.72+2.58+3=9.3 points in total and this is the only optimal order (you can calculate total scores for other 55 possible orders too see that they are lower). You should check points for problems 11 and 33 to see a paradox. There is 4<10 but 3.72>3 . It turns out that there is no paradox for c=0.625c=0.625 but there is a paradox for any bigger cc .

In the second sample, all 2424 orders are optimal.

In the third sample, even for c=1c=1 there is no paradox.

首页