Surveillance Posts
Time limit1.5sMemory limit1024 MB
Split border zones 1 to N into disjoint contiguous ranges, each with one post and at most P soldiers, and find the minimum total build cost.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Array
- Solved
- No attempts yet
Problem
The commander has received reports that enemy movements have turned ominous, and wants to place surveillance posts along the border so that every border zone is fully watched. There are border zones, numbered 1 through , lined up from left to right with a distance of 1 between neighboring zones. The length of each zone is 0. Building a post in zone costs , and each zone can hold at most one post.
Each post must have at least one soldier assigned as its squad leader, and the squad leader always watches the zone where the post is built. More soldiers can be assigned to a post so that it watches more zones. To watch one more zone at distance away, additional soldiers must be assigned. If the watch areas of two posts overlap, the zones can be confused, so the commander ordered that each post watch only a contiguous range of zones. However, each post can hold at most soldiers.
Find the minimum total cost needed to watch all border zones.
Input
The first line contains the number of border zones and the maximum number of soldiers per post, separated by a space.
The second line contains the build costs for zones through , separated by spaces.
Output
Print the minimum total cost needed to watch all border zones.