LG#P1209. 【GESP强化 五级】Barn Repair

提交0 通过0
通过率0%
时间限制1000ms
内存限制128MiB
    ID: 10255 传统题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 普及 上传者: 标签>GESPGESP强化C++c++编程题洛谷公开题搜索贪心USACO排序贪心算法

题目描述

题目描述

It was a dark and stormy night that ripped the roof and gates off the stalls that hold Farmer John's cows. Happily, many of the cows were on vacation, so the barn was not completely full.

The cows spend the night in stalls that are arranged adjacent to each other in a long line. Some stalls have cows in them; some do not. All stalls are the same width.

Farmer John must quickly erect new boards in front of the stalls, since the doors were lost. His new lumber supplier will supply him boards of any length he wishes, but the supplier can only deliver a small number of total boards. Farmer John wishes to minimize the total length of the boards he must purchase.

Given MM (1M501 \le M \le 50), the maximum number of boards that can be purchased; SS (1S2001 \le S \le 200), the total number of stalls; CC (1CS1 \le C \le S) the number of cows in the stalls; and the CC occupied stall numbers (1stall_numberS1 \le \text{stall\_number} \le S), calculate the minimum number of stalls that must be blocked in order to block all the stalls that have cows in them.

Print your answer as the total number of stalls blocked.

输入格式

  • Line 1: MM, SS, and CC (space separated).
  • Lines 2..C+1C+1: Each line contains one integer, the number of an occupied stall.

输出格式

A single line with one integer that represents the total number of stalls blocked.

输入输出样例

4 50 18
3 
4 
6 
8 
14
15 
16 
17 
21
25 
26 
27 
30 
31 
40 
41 
42 
43
25

说明/提示

One minimum arrangement is one board covering stalls 33-88, one covering 1414-2121, one covering 2525-3131, and one covering 4040-4343.

USACO Training Section 1.3.

1 1 1
1
1
42 4 1
1
1