Hotel Rewards
Time limit2sMemory limit512 MB
Given nightly hotel prices and a K-points-per-free-night reward rule, find the minimum total cost of the whole trip.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Greedy, Heap
- Solved
- No attempts yet
Problem
You are touring Europe for nights and you sleep in a different city every night. You have already picked the hotel for each city, so you know the price of the room you take on night for .
You book every room through a website that runs a rewards program. Each night you sleep in a hotel booked through that website you earn one point. Whenever your account holds at least points you may spend of them on one free night in any hotel. A free night earns no point.
For example, take and with prices , , , , and . Paying for the first four nights leaves four points in the account, and those cover the last two nights for free, for a total of . If instead you spend two of the three points earned in the first three nights on the fourth night, you can pay for the fifth night and use the last two points on the sixth. That plan costs , which is cheaper.
Write a program that finds the minimum possible total cost of your accommodation. Every hotel you want always has a room free for you, and the order of the cities cannot be changed.
Input
The first line contains two integers and , the number of nights of the trip and the number of points one free night costs ().
The second line contains integers , where is the price of the room you take on night ().
Output
Print one integer, the minimum total cost of the accommodation.