CF234F.Fence
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Vasya should paint a fence in front of his own cottage. The fence is a sequence of n wooden boards arranged in a single row. Each board is a 1 centimeter wide rectangle. Let's number the board fence using numbers 1, 2, ..., n from left to right. The height of the i-th board is h__i centimeters.
Vasya has a 1 centimeter wide brush and the paint of two colors, red and green. Of course, the amount of the paint is limited. Vasya counted the area he can paint each of the colors. It turned out that he can not paint over a square centimeters of the fence red, and he can not paint over b square centimeters green. Each board of the fence should be painted exactly one of the two colors. Perhaps Vasya won't need one of the colors.
In addition, Vasya wants his fence to look smart. To do this, he should paint the fence so as to minimize the value that Vasya called the fence unattractiveness value. Vasya believes that two consecutive fence boards, painted different colors, look unattractive. The unattractiveness value of a fence is the total length of contact between the neighboring boards of various colors. To make the fence look nice, you need to minimize the value as low as possible. Your task is to find what is the minimum unattractiveness Vasya can get, if he paints his fence completely.

The picture shows the fence, where the heights of boards (from left to right) are 2,3,2,4,3,1. The first and the fifth boards are painted red, the others are painted green. The first and the second boards have contact length 2, the fourth and fifth boards have contact length 3, the fifth and the sixth have contact length 1. Therefore, the unattractiveness of the given painted fence is 2+3+1=6.
瓦西娅需要粉刷自己小屋前的栅栏。该栅栏由 n 块木板组成,这些木板排成一列。每块木板是一个宽为 1 厘米的矩形。我们从左到右依次将木板编号为 1,2,…,n。第 i 块木板的高度为 hi 厘米。
瓦西娅有一把宽为 1 厘米的刷子,以及两种颜色的油漆:红色和绿色。当然,油漆的用量是有限的。瓦西娅计算了每种颜色所能涂刷的最大面积,结果发现他最多只能用红色油漆涂刷 a 平方厘米的栅栏,最多只能用绿色油漆涂刷 b 平方厘米的栅栏。栅栏的每一块木板必须且仅能涂上其中一种颜色(即红或绿),他可能并不需要使用其中某一种颜色。
此外,瓦西娅希望他的栅栏看起来美观。为此,他需以某种方式粉刷栅栏,使得他所定义的“栅栏不美观度”最小。瓦西娅认为:相邻两块木板若涂成不同颜色,则其交界处看起来不美观。栅栏的不美观度定义为所有相邻异色木板之间接触边界的总长度。为使栅栏尽可能美观,应使该不美观度尽可能小。你的任务是:在完全粉刷整个栅栏的前提下,求出瓦西娅所能达到的最小不美观度。

图中所示栅栏的各木板高度(从左至右)依次为 2,3,2,4,3,1。其中第 1 块与第 5 块木板涂成红色,其余涂成绿色。第 1 块与第 2 块木板之间的接触长度为 2,第 4 块与第 5 块之间的接触长度为 3,第 5 块与第 6 块之间的接触长度为 1。因此,该涂色方案对应的栅栏不美观度为 2+3+1=6。
输入格式
The first line contains a single integer n (1 ≤ n ≤ 200) — the number of boards in Vasya's fence.
The second line contains two integers a and b (0 ≤ a, b ≤ 4·104) — the area that can be painted red and the area that can be painted green, correspondingly.
The third line contains a sequence of n integers _h_1, _h_2, ..., h__n (1 ≤ h__i ≤ 200) — the heights of the fence boards.
All numbers in the lines are separated by single spaces.
第一行包含一个整数 n(1≤n≤200)——表示瓦夏的栅栏中木板的数量。
第二行包含两个整数 a 和 b(0≤a,b≤4⋅104)——分别表示可涂成红色的面积和可涂成绿色的面积。
第三行包含一个由 n 个整数 h1,h2,…,hn(1≤hi≤200)组成的序列——表示各栅栏木板的高度。
每行中的所有数字均以单个空格分隔。
输出格式
Print a single number — the minimum unattractiveness value Vasya can get if he paints his fence completely. If it is impossible to do, print - 1.
输出一个整数——即瓦夏将整个栅栏涂完后所能得到的最小“不美观度”值 V。若无法完成涂色,则输出 −1。
输入输出样例
输入#1
4 5 7 3 3 4 1
输出#1
3
输入#2
3 2 3 1 3 1
输出#2
2
输入#3
3 3 3 2 2 2
输出#3
-1
输入解题思路,AI测评打分。不知道怎么写?