模拟好题 CodeForces 864CBus
来源:互联网 发布:pdf.js 打开 word文档 编辑:程序博客网 时间:2024/06/05 05:48
C. Bus
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
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.
Input
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.
Output
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.
Examples
input
6 9 2 4
output
4
input
6 10 2 4
output
2
input
6 5 4 3
output
-1
Note
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.
mycode:
这里写代码片
include
include
include
include
include
include
- 模拟好题 CodeForces 864CBus
- 模拟好题 E
- Codeforces 864C Bus(模拟水题)
- Codeforces 好题
- codeforces 864C 模拟
- Codeforces--658C--Bear and Forgotten Tree 3(模拟&&技巧)(好题)
- Codeforces 677B Vanya and Food Processor (模拟的好题)
- Codeforces 492D Vanya and Computer Game【模拟+循环节+思维】好题~
- CBUS转MQTT
- [NOIP模拟][好题]Problem
- codeforces-703(好题)
- Codeforces好题专栏(前三道)
- codeforces 864D 模拟 + 贪心
- Codeforces 366E 模拟题
- CodeForces - 200ACinema模拟题
- Codeforces 390A( 模拟题)
- CodeForces - 404A(模拟题)
- CodeForces - 404B(模拟题)
- div 层基础知识
- RMQ模板题 poj3264 Balanced Lineup
- 剑指offer:数组中重复的数字
- 最大子段-n上找m个子段的和为最大-动态规划-二维dp+滚动数组dp优化
- 彻底剖析numpy的数值运算
- 模拟好题 CodeForces 864CBus
- C++文件操作与文件流学习
- 笔记
- 【Scikit-Learn 中文文档】最近邻
- <Java算法实现--LeetCode(4)(7)>2017-11-22
- Linux之Redhat中 Web端建立mysql数据库及论坛
- 一维字符串hash模板
- 连续子数组的最大和
- 11.22学习计划