CF864C.Bus
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys.
The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank.
There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline.
What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0.
一辆公交车沿坐标轴 Ox 从点 x=0 行驶至点 x=a。它从 x=0 出发,到达 x=a 后立即掉头,返回至 x=0;回到 x=0 后又立刻再次驶向 x=a,如此往复。因此,公交车在 x=0 与 x=a 之间往返行驶。从 x=0 到 x=a 或从 x=a 到 x=0 的一次完整行驶称为一趟行程。公交车总共需完成 k 趟行程。
公交车的油箱容量为 b 升汽油。每行驶一个单位距离恰好消耗 1 升汽油。公交车在开始第一趟行程时油箱是满的(即含 b 升汽油)。
在点 x=f 处设有一座加油站,该点位于 x=0 与 x=a 之间(即 0<f<a)。整条公交路线中除该站外再无其他加油站。公交车在任一方向途经该加油站时均可停车,并将油箱加满至 b 升(即加满后油箱含 b 升汽油)。
问:为完成全部 k 趟行程,公交车在点 x=f 处最少需要加油多少次?注意:第一趟行程始于点 x=0。
输入格式
The first line contains four integers a, b, f, k (0 < f < a ≤ 106, 1 ≤ b ≤ 109, 1 ≤ k ≤ 104) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys.
第一行包含四个整数 a、b、f、k(0<f<a≤106,1≤b≤109,1≤k≤104)——分别表示第一次公交行程的终点、公交车油箱的容量、加油站的位置以及所需的行程次数。
输出格式
Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1.
输出公交车完成 k 次行程所需的最少加油次数。如果公交车无法完成 k 次行程,则输出 -1。
输入输出样例
输入#1
6 9 2 4
输出#1
4
输入#2
6 10 2 4
输出#2
2
输入#3
6 5 4 3
输出#3
-1
说明/提示
In the first example the bus needs to refuel during each journey.
In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty.
In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
在第一个例子中,公交车每次行程都需要加油。
在第二个例子中,公交车可以在不加油的情况下行驶 10 单位距离。因此,公交车完成整个第一次行程,再行驶第二次行程的前 4 单位距离,到达加油站所在位置;随后可为油箱加满油,完成第二次行程,并继续行驶第三次行程的前 2 单位距离。此时,它将再次抵达加油站所在位置。接着,它可以将油箱加满至 10 升,从而完成第三次行程,并走完全第四次行程的全部路程。行程结束时,油箱恰好为空。
在第三个例子中,公交车无法完成全部 3 次行程:若它在第二次行程中加油,则加油后油箱中仅剩 5 升汽油,但公交车需再行驶 8 单位距离才能到达下一个加油站。
输入解题思路,AI测评打分。不知道怎么写?