304535: CF864C. Bus

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

Description

Bus

题意翻译

题意: 一辆汽车在x轴上从 x=0 处到 x=a 处往返k次旅行(从0->a算一次,从a->0算一次). 已知在开始时汽车油箱有b升油,汽车每行驶一单位距离消耗一升油,且在 x=f 处有加油站,每次经过 加油站都可以加满油或者不加油.问完成这k次旅行最少需要加油多少次? 输入: 四个数字a,b,f,k a是第一次旅行的终点(0<=a<=10^6) b是油箱容量(1<=b<=10^9) f是加油站的位置 k是旅行次数(1<=k<=10000) 输出: 若不能完成旅行,输出-1,否则输出最少的加油次数 Translated by 凌幽

题目描述

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 $ .

输入输出格式

输入格式


The first line contains four integers $ a $ , $ b $ , $ f $ , $ k $ ( $ 0<f<a<=10^{6} $ , $ 1<=b<=10^{9} $ , $ 1<=k<=10^{4} $ ) — 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.

输出格式


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.

输入输出样例

输入样例 #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.

Input

题意翻译

题意: 一辆汽车在x轴上从 x=0 处到 x=a 处往返k次旅行(从0->a算一次,从a->0算一次). 已知在开始时汽车油箱有b升油,汽车每行驶一单位距离消耗一升油,且在 x=f 处有加油站,每次经过 加油站都可以加满油或者不加油.问完成这k次旅行最少需要加油多少次? 输入: 四个数字a,b,f,k a是第一次旅行的终点(0<=a<=10^6) b是油箱容量(1<=b<=10^9) f是加油站的位置 k是旅行次数(1<=k<=10000) 输出: 若不能完成旅行,输出-1,否则输出最少的加油次数 Translated by 凌幽

加入题单

算法标签: