#P3035. [USACO11DEC] Umbrellas for Cows S
[USACO11DEC] Umbrellas for Cows S
Description
Today is a rainy day!Farmer John's cows, numbered , are not particularly fond of getting wet. The cows are standing in roofless stalls arranged on a number line. The stalls span X-coordinates from to . Cow stands at a stall on coordinate . No two cows share stalls.
In order to protect the cows from the rain, Farmer John wants to buy them umbrellas. An umbrella that spans coordinates to has a width of . It costs to buy an umbrella of width . Larger umbrellas do not necessarily cost more than smaller umbrellas.
Help Farmer John find the minimum cost it takes to purchase a set of umbrellas that will protect every cow from the rain. Note that the set of umbrellas in an optimal solution might overlap to some extent.
Input Format
-
Line : Two space-separated integers: and .
-
Lines to : Line contains a single integer: .
-
Lines to : Line contains a single integer: .
Output Format
- Line 1: A single integer that is the minimum cost needed to purchase umbrellas for all the cows.
6 12
1
2
11
8
4
12
2
3
4
4
8
9
15
16
17
18
19
19
9
Hint
There are stalls, and stalls and contain cows. An umbrella covering one stall costs , an umbrella covering two stalls costs , and so on.
By purchasing a size umbrella, a size umbrella, and a size umbrella, it is possible to cover all the cows at a cost of :
UUUUUUUUUU U UUUU
C C C C C C
|--|--|--|--|--|--|--|--|--|--|--|
1 2 3 4 5 6 7 8 9 10 11 12
C represents a cow and U represents a part of an umbrella.
京公网安备 11011102002149号