欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1113A.Sasha and His Trip
Sasha and His Trip
Sasha is a very happy guy, that's why he is always on the move. There are cities in the country where Sasha lives. They are all located on one straight line, and for convenience, they are numbered from to in increasing order. The distance between any two adjacent cities is equal to kilometer. Since all roads in the country are directed, it's possible to reach the city from the city only if .
Once Sasha decided to go on a trip around the country and to visit all cities. He will move with the help of his car, Cheetah-2677. The tank capacity of this model is liters, and it spends exactly liter of fuel for kilometer of the way. At the beginning of the journey, the tank is empty. Sasha is located in the city with the number and wants to get to the city with the number . There is a gas station in each city. In the -th city, the price of liter of fuel is dollars. It is obvious that at any moment of time, the tank can contain at most liters of fuel.
Sasha doesn't like to waste money, that's why he wants to know what is the minimum amount of money is needed to finish the trip if he can buy fuel in any city he wants. Help him to figure it out!
Input
The first line contains two integers and (, ) — the number of cities in the country and the capacity of the tank.
Output
Print one integer — the minimum amount of money that is needed to finish the trip.
Note
In the first example, Sasha can buy liters for dollars ( dollar per liter) in the first city, drive to the second city, spend liter of fuel on it, then buy liter for dollars in the second city and then drive to the -th city. Therefore, the answer is .
In the second example, the capacity of the tank allows to fill the tank completely in the first city, and drive to the last city without stops in other cities.
Samples
4 2
4
7 6
6
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |