CF639E.Bear and Paradox

省选/NOI-

通过率:0%

时间限制:3.50s

内存限制:256MB

AC君温馨提醒

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

题目描述

Limak is a big polar bear. He prepared n problems for an algorithmic contest. The i-th problem has initial score p__i. Also, testers said that it takes t__i minutes to solve the i-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 c in this statement.

Let T denote the total number of minutes needed to solve all problems (so, T = _t_1 + _t_2 + ... + t__n). The contest will last exactly T minutes. So it's just enough to solve all problems.

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

Let's assume that c is fixed. During a contest a participant chooses some order in which he or she solves problems. There are 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 t__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 i and j such that p__i < p__j Limak wouldn't be happy to see a participant with strictly more points for problem i than for problem j. He calls such a situation a paradox.

It's not hard to prove that there will be no paradox for c = 0. The situation may be worse for bigger c. What is the maximum real value c (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 c as described) always exists.

Limak 是一只大型北极熊。他为一场算法竞赛准备了 nn 道题目。第 ii 道题的初始分数为 pip_i,同时测试人员指出解决第 ii 道题需要 tit_i 分钟。题目并不一定按难度排序,因此较难的题目可能具有更小的初始分数;但此时已无法更改——Limak 已经公布了所有题目的初始分数。不过,仍然可以调整扣分速率,本题中用常数 cc 表示。

令 TT 表示解决所有题目所需的总时间(即 T=t1+t2+⋯+tnT = t_1 + t_2 + \dots + t_n)。比赛时长恰好为 TT 分钟,因此参赛者刚好有足够时间解决全部题目。

每道题的得分随解题时间线性衰减。若在 xx 分钟后解决第 ii 道题,则所得分数恰好为

其中

是 Limak 必须选定的某个实常数。

假设 cc 已固定。在比赛中,参赛者可自行选择解题顺序。共有 n!n! 种可能的顺序,每种顺序对应一个总得分(不一定是整数)。若某顺序给出的总得分不低于其余任意顺序所得总得分,则称该顺序为最优顺序。显然至少存在一个最优顺序;但最优顺序也可能不止一个。

Limak 假设每位参赛者均能在比赛开始之初准确估计出每个 tit_i,并从中选择某个最优顺序;他还假设测试人员对每道题所需解决时间的预测完全正确。

对于两个不同的题目 ii 和 jj,若满足 pi<pjp_i < p_j,而某位参赛者在解决题目 ii 时获得的分数却严格大于解决题目 jj 时获得的分数,则 Limak 将对此感到不满。他将此类情形称为悖论(paradox)。

不难证明:当 c=0c = 0 时,不会出现悖论。而随着 cc 增大,悖论可能出现的概率会升高。那么,在保证对任意最优解题顺序均不会出现悖论的前提下,cc 的最大实数值是多少?(注意:要求
)

可以证明:上述所求的最大 cc 值恒存在。

输入格式

The first line contains one integer n (2 ≤ n ≤ 150 000) — the number of problems.

The second line contains n integers _p_1, _p_2, ..., p__n (1 ≤ p__i ≤ 108) — initial scores.

The third line contains n integers _t_1, _t_2, ..., t__n (1 ≤ t__i ≤ 108) where t__i is the number of minutes needed to solve the i-th problem.

第一行包含一个整数 nn(2≤n≤150 0002 \leq n \leq 150\,000)——问题的数量。

第二行包含 nn 个整数 p1, p2, ..., pnp_1,\,p_2,\,...,\,p_n(1≤pi≤1081 \leq p_i \leq 10^8)——初始分值。

第三行包含 nn 个整数 t1, t2, ..., tnt_1,\,t_2,\,...,\,t_n(1≤ti≤1081 \leq t_i \leq 10^8),其中 tit_i 表示解决第 ii 个问题所需的分钟数。

输出格式

Print one real value on a single line — the maximum value of c 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 10 - 6.

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

在单独一行中输出一个实数值——满足条件 cc 的最大值,使得 ,且不存在具有悖论的最优排序。若你的答案的绝对误差或相对误差不超过 10−610^{-6},则视为正确。

即:假设你的答案为 aa,评测组的标准答案为 bb。当且仅当 时,评测程序将判定你的答案正确。

输入输出样例

  • 输入#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 3 problems. The first is (4, 1) (initial score is 4 and required time is 1 minute), the second problem is (3, 1) and the third one is (10, 8). The total time is T = 1 + 1 + 8 = 10.

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

  1. solved 1 minute after the start:
  2. solved 2 minutes after the start:
  3. solved 10 minutes after the start:

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

In the second sample, all 24 orders are optimal.

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

在第一个样例中,共有 3 道题目。第一道题为 (4, 1)(4,\,1)(初始得分为 4,所需时间为 1 分钟),第二道题为 (3, 1)(3,\,1),第三道题为 (10, 8)(10,\,8)。总时间为 T=1+1+8=10T = 1 + 1 + 8 = 10。

我们来说明当 c=0.7c = 0.7 时存在悖论。按顺序 1、2、3 解题可获得最高总得分,其值等于以下各项之和:

  1. 在开始后 1 分钟解出:
  2. 在开始后 2 分钟解出:
  3. 在开始后 10 分钟解出:

因此,该顺序共得分为 3.72+2.58+3=9.33.72 + 2.58 + 3 = 9.3 分,且这是唯一最优的解题顺序(你也可以计算其余 5 种可能顺序的总得分,验证它们均更低)。你需要比较题目 1 和题目 3 的得分以观察悖论:尽管 4<104 < 10,却有 3.72>33.72 > 3。事实上,当 c=0.625c = 0.625 时不存在悖论,但对任意大于 0.6250.625 的 cc 均存在悖论。

在第二个样例中,全部 24 种顺序均为最优。

在第三个样例中,即使 c=1c = 1 也不存在悖论。

输入解题思路,AI测评打分。不知道怎么写?

首页