308758: CF1571B. Epic Novel

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Epic Novel

题意翻译

Alex 买了一本 $n$ 章的小说,为了保证内容的连续性,他不会跳章看,也不会回头看,每一章可能会读一天或多于一天,但一天不会读多页。第一天他读第 $1$ 章。 设 $v_i$ 表示 Alex 第 $i$ 天读的章节,举几个例子来帮助你更好的理解题意: - $v_1 = 1, v_2 = 1, v_3 = 2, v_4 = 3, v_5 = 3$——可行的:第 $1,2$ 天读了第 $1$ 章,第 $3$ 天读了第 $2$ 章,第 $4,5$ 天读了第 $3$ 章。 - $v_1 = 2, v_2 = 2, v_3 = 3$——不可行:必须从第 $3$ 章开始读。 - $v_1 = 1, v_2 = 2, v_3 = 3, v_4 = 4$——不可行:不能回头看,这里看完第 $3$ 章又回头看了第 $1$ 章。 - $v_1 = 1, v_2 = 3$——不可行:不能跳章看,这里从第 $1$ 章直接跳到了第 $3$ 章。 已知 Alex 在第 $a$ 天读第 $v_a$ 章,第 $c$ 天读第 $v_c$ 章,请判断在第 $b\ (a < b < c)$ 天他在读第几章,输出任意可能解。 多组($t$ 组)数据。 数据范围:$1\le t\le 100$,$1\le n\le 100$,$1\le a\le 98$,$1\le v_a \le a$,$a+2\le c\le 100$,$v_a\le v_c\le c$。 translator:[219791](https://www.luogu.com.cn/user/219791)。

题目描述

Alex has bought a new novel that was published in $ n $ volumes. He has read these volumes one by one, and each volume has taken him several (maybe one) full days to read. So, on the first day, he was reading the first volume, and on each of the following days, he was reading either the same volume he had been reading on the previous day, or the next volume. Let $ v_i $ be the number of the volume Alex was reading on the $ i $ -th day. Here are some examples: - one of the possible situations is $ v_1 = 1 $ , $ v_2 = 1 $ , $ v_3 = 2 $ , $ v_4 = 3 $ , $ v_5 = 3 $ — this situation means that Alex has spent two days ( $ 1 $ -st and $ 2 $ -nd) on the first volume, one day ( $ 3 $ -rd) on the second volume, and two days ( $ 4 $ -th and $ 5 $ -th) on the third volume; - a situation $ v_1 = 2 $ , $ v_2 = 2 $ , $ v_3 = 3 $ is impossible, since Alex started with the first volume (so $ v_1 $ cannot be anything but $ 1 $ ); - a situation $ v_1 = 1 $ , $ v_2 = 2 $ , $ v_3 = 3 $ , $ v_4 = 1 $ is impossible, since Alex won't return to the first volume after reading the third one; - a situation $ v_1 = 1 $ , $ v_2 = 3 $ is impossible, since Alex doesn't skip volumes. You know that Alex was reading the volume $ v_a $ on the day $ a $ , and the volume $ v_c $ on the day $ c $ . Now you want to guess which volume was he reading on the day $ b $ , which is between the days $ a $ and $ c $ (so $ a < b < c $ ). There may be some ambiguity, so you want to make any valid guess (i. e. choose some volume number $ v_b $ so it's possible that Alex was reading volume $ v_a $ on day $ a $ , volume $ v_b $ on day $ b $ , and volume $ v_c $ on day $ c $ ).

输入输出格式

输入格式


Each test contains multiple test cases. The first line contains the number of test cases $ t $ ( $ 1 \le t \le 100 $ ). Description of the test cases follows. The first line of each test case contains a single integer $ n $ ( $ 1 \le n \le 100 $ ) — the number of volumes the novel consists of. The second line of each test case contains two integers $ a $ and $ v_a $ ( $ 1 \le a \le 98 $ ; $ 1 \le v_a \le a $ ) denoting that Alex was reading volume $ v_a $ at day $ a $ . The third line of each test case contains two integers $ c $ and $ v_c $ ( $ a + 2 \le c \le 100 $ ; $ v_a \le v_c \le c $ ) denoting that Alex was reading volume $ v_c $ at day $ c $ . The fourth line of each test case contains one integer $ b $ ( $ a < b < c $ ) — the day you are interested in. It's guaranteed that the input is not controversial, in other words, Alex could read volume $ v_a $ at day $ a $ and volume $ v_c $ at day $ c $ .

输出格式


For each test case, print the possible index of volume Alex could read at day $ b $ . If there are multiple answers, print any.

输入输出样例

输入样例 #1

4
1
1 1
100 1
99
4
10 1
20 4
16
100
1 1
100 100
42
100
1 1
100 2
99

输出样例 #1

1
2
42
1

说明

In the first test case, since Alex was reading volume $ 1 $ both at day $ 1 $ and at day $ 100 $ then he was reading volume $ 1 $ at any day between them. In the second test case, Alex could read any volume from $ 1 $ to $ 4 $ at day $ 16 $ . For example, he could read volume $ 1 $ from day $ 1 $ to day $ 15 $ , volume $ 2 $ at days $ 16 $ and $ 17 $ , volume $ 3 $ at day $ 18 $ and volume $ 4 $ at days $ 19 $ and $ 20 $ . In the third test case, there is only one possible situation: Alex read one volume per day, so at day $ 42 $ he read volume $ 42 $ .

Input

题意翻译

Alex 买了一本 $n$ 章的小说,为了保证内容的连续性,他不会跳章看,也不会回头看,每一章可能会读一天或多于一天,但一天不会读多页。第一天他读第 $1$ 章。 设 $v_i$ 表示 Alex 第 $i$ 天读的章节,举几个例子来帮助你更好的理解题意: - $v_1 = 1, v_2 = 1, v_3 = 2, v_4 = 3, v_5 = 3$——可行的:第 $1,2$ 天读了第 $1$ 章,第 $3$ 天读了第 $2$ 章,第 $4,5$ 天读了第 $3$ 章。 - $v_1 = 2, v_2 = 2, v_3 = 3$——不可行:必须从第 $3$ 章开始读。 - $v_1 = 1, v_2 = 2, v_3 = 3, v_4 = 4$——不可行:不能回头看,这里看完第 $3$ 章又回头看了第 $1$ 章。 - $v_1 = 1, v_2 = 3$——不可行:不能跳章看,这里从第 $1$ 章直接跳到了第 $3$ 章。 已知 Alex 在第 $a$ 天读第 $v_a$ 章,第 $c$ 天读第 $v_c$ 章,请判断在第 $b\ (a < b < c)$ 天他在读第几章,输出任意可能解。 多组($t$ 组)数据。 数据范围:$1\le t\le 100$,$1\le n\le 100$,$1\le a\le 98$,$1\le v_a \le a$,$a+2\le c\le 100$,$v_a\le v_c\le c$。 translator:[219791](https://www.luogu.com.cn/user/219791)。

加入题单

算法标签: