QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 1024 MB Total points: 100

#4823. No!

统计

给定 $n$ 面墙,第 $i$ 面墙的高度为 $h_i$,强度为 $s_i$。你需要将它们从左到右排成一行。

在接下来的 $q$ 天里,每天晚上都会刮风。由于天气预报不准确,你无法确定每晚风的强度。

在第 $k$ 天的早晨,安全中心会在地面的最左侧建造一面高度为 $h_k'$ 的无限坚固的墙。随后,你可以将你拥有的 $n$ 面墙以任意顺序排列在这面墙的右侧。注意,安全中心每天建造的墙仅在当天有效。在第二天建造新墙之前,原有的墙会被移除。

晚上,强度为 $v$ 的风会从最左侧吹来。对于每一面墙 $i$,从左往右数,第 $i$ 面墙受到的冲击力为 $\Delta_i = v \cdot \max(0, h_i - \max_{0 \le j < i} h_j)$。其中,墙 $0$ 是安全中心建造的墙:在第 $k$ 天,其高度为 $h_k'$,且强度无限。如果对于某面墙 $i$,满足 $\Delta_i > s_i$,则该墙会倒塌,你将遭受严重的经济损失。

你希望知道,对于每一天,如果你能最优地排列这 $n$ 面墙,你所能承受的最大风力是多少。

可以证明,答案要么是无穷大,要么可以表示为 $r = a/b$ 的形式,其中 $a$ 和 $b$ 是互质的正整数。你只需要输出 $a$ 和 $b$ 的值。

输入格式

第一行包含两个整数 $n$ 和 $q$ ($1 \le n, q \le 5 \cdot 10^5$)。

接下来的 $n$ 行,每行包含两个整数 $h_i$ 和 $s_i$ ($1 \le h_i \le 4 \cdot 10^6, 1 \le s_i \le 10^9$),表示第 $i$ 面墙的高度和强度。

接下来的 $q$ 行,每行包含一个整数 $h_k'$ ($1 \le h_k' \le 4 \cdot 10^6$),表示安全中心在第 $k$ 天建造的无限坚固墙的高度。

输出格式

输出 $q$ 行,每行以不可约分数 “$a/b$” 的格式输出,中间没有空格,表示答案的值为 $r = a/b$。如果墙可以承受任意强度的风,请输出无穷大为 “1/0”。

样例

样例 1

4 5
3 5
4 3
2 5
6 3
5
2
3
7
2

样例 1 输出

3/1
3/2
3/2
1/0
3/2

样例 2

5 6
10 6
3 7
6 15
7 6
8 15
5
3
9
7
7
9

样例 2 输出

3/1
3/1
6/1
3/1
3/1
6/1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.