#abc356g. G - Freestyle

G - Freestyle

Score : 575575 points

问题陈述

高桥可以以 NN 种不同的方式游泳。 当他以第 ii 种方式游泳时,他每秒钟消耗 AiA_i 点体力,并且每秒钟前进 BiB_i 米。

回答 QQ 个查询。第 ii 个查询如下:

  • 确定是否可能在总体力消耗不超过 CiC_i 的情况下前进 DiD_i 米。如果可能,找出所需的最少秒数。

在这里,他可以自由地组合不同的游泳方式,并且切换方式的时间可以忽略不计。 具体来说,他可以按照以下步骤游泳:

  • 选择一个正整数 mm,一个长度为 mm 的正实数序列 t=(t1,t2,,tm)t=(t_1,t_2,\dots,t_m),以及一个长度为 mm 的整数序列 x=(x1,x2,,xm)x=(x_1,x_2,\dots,x_m),其中每个元素都在 11NN(包括 11NN)之间。
  • 然后,按照顺序 i=1,2,,mi=1,2,\dots,m 以第 xix_i 种方式游泳 tit_i 秒。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

Takahashi can swim in NN different styles.
When he swims in the ii-th style, he consumes AiA_i stamina per second and advances BiB_i meters per second.

Answer QQ queries. The ii-th query is as follows:

  • Determine if it is possible to advance DiD_i meters while keeping the total stamina consumption at most CiC_i. If it is possible, find the minimum number of seconds required.

Here, he can freely combine different swimming styles, and the time to switch styles is negligible.
Specifically, he can swim using the following steps:

  • Choose a positive integer mm, a sequence of positive real numbers t=(t1,t2,,tm)t=(t_1,t_2,\dots,t_m) of length mm, and a sequence of integers x=(x1,x2,,xm)x=(x_1,x_2,\dots,x_m) of length mm where each element is between 11 and NN, inclusive.
  • Then, swim in the xix_i-th style for tit_i seconds in the order i=1,2,,mi=1,2,\dots,m.

Constraints

  • All input values are integers.
  • 1N2×1051 \le N \le 2 \times 10^5
  • 1Ai,Bi1091 \le A_i, B_i \le 10^9
  • 1Q2×1051 \le Q \le 2 \times 10^5
  • 1Ci,Di1091 \le C_i, D_i \le 10^9

Input

The input is given from Standard Input in the following format:

NN

A1A_1 B1B_1

A2A_2 B2B_2

\vdots

ANA_N BNB_N

QQ

C1C_1 D1D_1

C2C_2 D2D_2

\vdots

CQC_Q DQD_Q

Output

Print QQ lines in total.
For the ii-th query, print the answer in the ii-th line as follows:

  • If it is impossible to advance DiD_i meters while keeping the total stamina consumption at most CiC_i, print -1.
  • Otherwise, print the minimum required time. The output is considered correct if the absolute or relative error between the printed value and the true answer is at most 10910^{-9}.

Sample Input 1

4
1 2
2 3
3 3
4 4
5
4 7
7 7
49 100
1000 500
4 5

Sample Output 1

3.000000000000000000
1.750000000000000000
-1
125.000000000000000000
1.500000000000000000

In this input, Takahashi can swim in the following four styles:

  • Consumes 11 stamina and advances 22 meters per second.
  • Consumes 22 stamina and advances 33 meters per second.
  • Consumes 33 stamina and advances 33 meters per second.
  • Consumes 44 stamina and advances 44 meters per second.

This input contains five queries.

  • For the first query, C1=4,D1=7C_1=4, D_1=7.
    • Choose t=(1,2)t=(1,2) and x=(2,1)x=(2,1). Takahashi swims as follows:
      • In the first 11 second, he consumes 22 stamina and advances 33 meters.
      • In the next 22 seconds, he consumes 22 stamina and advances 44 meters.
    • In total, he consumes 44 stamina and advances 77 meters. The required time is 33 seconds, which is the minimum.
  • For the second query, C2=7,D2=7C_2=7, D_2=7.
    • Choose t=(7/4)t=(7/4) and x=(4)x=(4). Takahashi swims as follows:
      • In the first 7/47/4 seconds, he consumes 77 stamina and advances 77 meters.
    • In total, he consumes 77 stamina and advances 77 meters. The required time is 7/47/4 seconds, which is the minimum.
  • For the third query, C3=49,D3=100C_3=49, D_3=100.
    • No matter how Takahashi swims, it is not possible to advance 100100 meters while keeping the total stamina consumption at most 4949.
  • For the fourth query, C4=1000,D4=500C_4=1000, D_4=500.
    • Choose t=(125)t=(125) and x=(4)x=(4). Takahashi swims as follows:
      • In the first 125125 seconds, he consumes 500500 stamina and advances 500500 meters.
    • In total, he consumes 500500 stamina and advances 500500 meters. The required time is 125125 seconds, which is the minimum.
  • For the fifth query, C5=4,D5=5C_5=4, D_5=5.
    • Choose t=(1/2,1)t=(1/2,1) and x=(4,2)x=(4,2). Takahashi swims as follows:
      • In the first 1/21/2 seconds, he consumes 22 stamina and advances 22 meters.
      • In the next 11 second, he consumes 22 stamina and advances 33 meters.
    • In total, he consumes 44 stamina and advances 55 meters. The required time is 3/23/2 seconds, which is the minimum.