QOJ.ac

QOJ

実行時間制限: 1.0 s メモリ制限: 1024 MB 満点: 100 ハック可能 ✓

#17871. 旭日

統計

Joon 明天有一场期中考试,但他什么都还没复习。因此,他决定通宵学习。他向自己保证,在太阳升起之前绝不停止学习。

Joon 的家在群山之中。为了方便起见,我们假设 Joon 居住在一个二维直角坐标系中。山脉位于 $y \ge 0$ 的区域,起点为 $x = a_0$,其边界由 $2n$ 条平行于 $y = x$ 或 $y = -x$ 的线段组成。

更具体地说,山脉的边界可以由额外的 $(2n - 1)$ 个整数来描述,其中第 $i$ 个数 $a_i$ 是山脉第 $i$ 个拐点的 $x$ 坐标。边界线起点为 $(a_0, 0)$,平行于 $y = x$ 延伸,直到其 $x$ 坐标达到 $a_1$;然后平行于 $y = -x$ 延伸,直到其 $x$ 坐标达到 $a_2$,依此类推。在最后一步之后,折线平行于 $y = -x$ 延伸,直到与 $x$ 轴相交。

山脉的内部是边界下方、 $x$ 轴上方的区域。因此,内部和边界是不相交的。

在 $x = a_0$ 和 $x = a_{2n-1}$ 之间的某个位置,Joon 的家位于山脉的边界上。与山脉相比,他的家的大小可以忽略不计。

目前,太阳位于原点,并以每分钟 $1$ 单位的速度垂直向上($+y$ 方向)升起。如果连接 Joon 的家和太阳的线段不与山脉的内部相交,Joon 就能看到太阳。Joon 已经精疲力竭,想知道他什么时候可以停止学习。但正如你所料,他已经糊涂了,所以他做不出这么难的数学题。帮帮他吧!

输入格式

第一行包含一个整数 $n$ ($1 \le n \le 10^3$)。

第二行包含 $2n$ 个整数,其中第 $i$ 个是整数 $a_{i-1}$ ($1 \le a_0 < \dots < a_{2n-1} \le 10^6$)。

最后一行包含一个整数 $x$,表示 Joon 家的 $x$ 坐标 ($a_0 \le x \le a_{2n-1}$)。

保证山脉的边界位于 $y \ge 0$ 的区域内。

输出格式

输出恰好一个整数 $m$,表示 Joon 在 $m$ 分钟后能看到太阳的最小整数。

样例

输入样例 1

2
1 4 6 7
7

输出样例 1

5

输入样例 2

2
3 4 5 7
7

输出样例 2

0

输入样例 3

3
4 9 12 13 14 16
15

输出样例 3

8

说明

图:第一个样例的示意图。

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.