当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

5163:Taking Bus

题目描述
Bestland has a very long road and there are \(n\) bus station along the road, which are numbered 1 to \(n\) from left to right. There are \(m\) persons wanting to take the bus to some other station. You task is to find the time needed for each person. Note: All the other information you need is below. Please read the statment carefully.
输入解释
There are multiple test cases. The first line of input contains an integer \(T\ (1 \le T \le 60)\), indicating the number of test cases. For each test case: The first line contains two integers \(n \text{ and } m \ (2 \le n, m \le 10^5)\), indicating the number of bus stations and number of people. In the next line, there are \(n - 1\) integers, \(d_1, d_2, \dots, d_{n-1}\) (\(1 \le d_i \le 10^9\)). The \(i\)-th integer means the distance between bus station \(i\) and \(i + 1\) is \(d_i\) (\(1 \le i < n\)). In the next \(m\) lines, each contains two integers \(x_i\) and \(y_i\) (\(1 \le x_i, y_i \le n, x_i \ne y_i\)), which means \(i\)-th person is in bus station \(x_i\) and wants goto bus station \(y_i\). \((1 \le i \le m)\)

What else you should know is that for the \(i\)-th person, the bus starts at bus station \(((i - 1)\text{ mod } n) + 1\) and drives to right. When the bus arrives at station \(n\), it will turn around and drive from right to left. Similarly, When the bus arrives at station \(1\), it will turn around and drive from left to right. You can assume that the bus drives one meter per second. And you should only consider the time that the bus drives and ignore the others.
输出解释
For each person, you should output one integer which is the minimum time needed before arriving bus station \(y_i\).
输入样例
1
7 3
2 3 4 3 4 5
1 7
4 5
5 4
输出样例
21
10
28
提示
For the first person, the bus starts at bus station 1, and the person takes in bus at time 0. After 21 seconds, the bus arrives at bus station 7. So the time needed is 21 seconds. For the second person, the bus starts at bus station 2. After 7 seconds, the bus arrives at bus station 4 and the person takes in the bus. After 3 seconds, the bus arrives at bus station 5. So the time needed is 10 seconds. For the third person, the bus starts at bus station 3. After 7 seconds, the bus arrives at bus station 5 and the person takes in the bus. After 9 seconds, the bus arrives at bus station 7 and the bus turns around. After 12 seconds, the bus arrives at bus station 4. So the time needed is 28 seconds.
来自杭电HDUOJ的附加信息
Recommend hujie

该题目是Virtual Judge题目,来自 杭电HDUOJ

题目来源 BestCoder Round #27

源链接: HDU-5163

最后修改于 2020-10-25T23:20:19+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
10000/5000MS(Java/Others) 32768/32768K(Java/Others)