Frequent Flier
Time limit2sMemory limit2048 MB
Given monthly flight counts, find the fewest flights you must pay for when every m consecutive months requires at least k paid flights or all flights in that span.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Sliding window, Prefix sum
- Solved
- No attempts yet
Problem
An airline runs a strange new rewards program that gives travelers free flights.
The program is set by two integers and . In any consecutive months, you must pay for at least of your flights. If there are fewer than flights in that span, you pay for all of them. The other flights in that span are free. This rule also applies to every -month span that starts before your first flight.
You have a schedule of how many flights you take in each of the next months. Find the minimum number of flights you must pay for.
Input
The first line contains three integers , () and (). Here is the number of consecutive months with planned flights, and and are the program parameters. Each of the next lines contains an integer (), the number of flights planned for that month.
Output
Output a single integer, the minimum number of planned flights you must pay for.