QOJ.ac

QOJ

Time Limit: 5 s Memory Limit: 10 MB Total points: 100

#400. 鸟类学家

Statistics

鸟类学家 Byteasar 偶然发现了一些关于“数码鸽”(Ectopistes digitorius,一种早已灭绝的 Byteotian 鸟类)的历史记录。据记载,这种鸟类有着不同寻常的求偶仪式。仪式涉及 $n$ 只雄鸟和 $m$ 只雌鸟。为了方便描述,我们将雄鸟编号为 $1$ 到 $n$,雌鸟编号为 $n+1$ 到 $n+m$。所有鸟类围成一个圆圈,按 $1$ 到 $n+m$ 的顺序排列,并唱起求偶歌。

数码鸽有两种不同的求偶歌:名为“可爱的鸽子”(Lovely pigeon)的歌,包含 $a$ 个音节;名为“哦,我的小斑鸠”(Oh my doveling)的歌,包含 $b$ 个音节。鸟儿们按圆圈的顺序依次唱出一个音节,从 1 号鸟开始唱“可爱的鸽子”的第一个音节。唱出求偶歌最后一个音节的鸟会飞走,剩下的鸟继续从离开的那只鸟的下一位开始唱歌。此外,如果离开的鸟是雄性,下一首求偶歌将是“可爱的鸽子”;如果离开的鸟是雌性,下一首求偶歌将是“哦,我的小斑鸠”。

Byteasar 想知道第 $k$ 只飞走的鸟是哪一只。请编写一个程序,输出他感兴趣的那只鸟的编号。

输入格式

标准输入的第一行也是唯一一行包含五个正整数 $n, m, a, b$ 和 $k$ ($k, a, b \le n+m$),用空格分隔,分别表示参与求偶仪式的雄鸟数量、雌鸟数量、“可爱的鸽子”歌的音节数、“哦,我的小斑鸠”歌的音节数,以及 Byteasar 感兴趣的鸟的序号。

输出格式

标准输出的第一行也是唯一一行应输出一个整数:第 $k$ 只飞走的鸟的编号。

样例

样例输入 1

4 6 3 5 6

样例输出 1

8

说明

样例解释:共有四只雄鸟和六只雌鸟。雄鸟编号为 $1, \dots, 4$,雌鸟编号为 $5, \dots, 10$。“可爱的鸽子”歌有三个音节,而“哦,我的小斑鸠”歌有五个音节。Byteasar 想知道第六只飞走的鸟是谁。

下图描绘了连续演唱的求偶歌。雄鸟编号为黑色,雌鸟编号为灰色:

第一首歌由 3 号鸟(雄性)唱完,所以第二首歌是“可爱的鸽子”。这首歌由 6 号鸟(雌性)唱完,所以第三首歌是“哦,我的小斑鸠”,它有五个音节。这首歌由 1 号鸟(雄性)唱完,所以下一首歌是“可爱的鸽子”,由 2、4 和 5 号鸟演唱。注意,已经飞走的鸟不再参与唱歌。

子任务

测试集由以下子任务组成。每个子任务内可能包含多个测试点。所有测试点均满足:$1 \le n, m \le 10^9$ 且 $1 \le a, b \le 10\,000$。

子任务 条件 分值
1 $n + m \le 1000$ 12
2 $n + m \le 250\,000$ 20
3 $n + m \le 5\,000\,000, k \le 1\,000\,000$ 18
4 $k \le 3\,000\,000$ 22
5 无额外条件 28

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.