#P9668. [ICPC2022 Jinan R] Torch
[ICPC2022 Jinan R] Torch
题目描述
Prof. Pang and Prof. Shou go to explore a cave together. Prof. Pang walks ahead of Prof. Shou.
Each of them has a torch for illumination. The torches need fuel to burn. Prof. Pang's torch can burn for seconds once it has been refilled, and it takes seconds to refuel the torch after it burns out. Prof. Shou's torch can burn for seconds once it has been refilled, and it takes seconds to refuel the torch after it burns out. The person who is refueling the torch cannot walk simultaneously. For safety reasons, they cannot refuel the torch until the fuel runs out.
Because Prof. Pang is too fat and the cave is too narrow, Prof. Shou cannot surpass Prof. Pang during the exploration, which means that Prof. Shou is at least 1 unit behind Prof. Pang.
Each of them can walk forward a distance of 1 unit per second when his torch is burning. Every second, Prof. Pang moves first, then Prof. Shou does. In order to get to their destination earlier, they will move as long as they can walk forward.
Now Prof. Shou has questions, and for the -th question, he wants to know that at time , how many units of the distance he has moved forward from the starting point? Prof. Shou starts 1 unit behind Prof. Pang. The initial time is 0. Both Prof. Pang and Prof. Shou refueled the torch before the initial time.
输入格式
The first line contains one integer , the number of test cases.
For each test case, the first line contains 5 integers $a_1, b_1, a_2, b_2, n~(1 \le a_1, b_1, a_2, b_2, n \le 10^6)$ denoting the time Prof. Pang's torch can burn, the time for Prof. Pang to refuel his torch, the time Prof. Shou's torch can burn, the time for Prof. Shou to refuel his torch, and the number of Prof. Shou's queries. Each of the next lines describes a query. Query is denoted by one integer .
It is guaranteed that over all test cases, each of the following numbers is no more than :
- the sum of ,
- the sum of ,
- the sum of ,
- the sum of ,
- and the sum of .
输出格式
For each query, print one line containing the answer -- the number of units that Prof. Shou has walked forward from the starting point.
题目大意
题目描述
胖子和瘦子在一个山洞里行走,胖子在瘦子前面。每个人都有一支火把。
胖子的火把填满燃料后可以燃烧 秒,在熄灭后需要花费 秒填充燃料。
瘦子的火把填满燃料后可以燃烧 秒,在熄灭后需要花费 秒填充燃料。
每个人只能在自己的火把燃烧时前进,速度为 。
因为胖子太胖,所以瘦子只能跟在胖子后面而不能超过胖子。
每一秒胖子先移动,之后瘦子再移动。
初始时两个人的火把都已经填满了燃料,瘦子在胖子后面 。
给定 个询问,每次给一个正整数 ,表示查询第 秒后,瘦子的移动距离。
输入格式
本题包含多组测试数据
第一行一个正整数 ,表示数据组数。
对于每组数据:
第一行五个正整数 ,含义见题目描述。
接下来 行,每行一个正整数 ,表示询问。
输出格式
每组数据输出 行,表示每个询问的答案,即第 秒后瘦子的移动距离。
数据范围
下面 表示所有数据的 之和, 同理。
,,$\sum a_1, \sum b_1, \sum a_2, \sum b_2, \sum n \le 10^6$,。
3
2 3 2 4 2
7
8
1 1 1 1 2
3
4
9 7 10 3 5
5
10
20
30
50
3
4
2
2
5
9
13
18
28