CF998B.Cutting
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are a lot of things which could be cut — trees, paper, "the rope". In this problem you are going to cut a sequence of integers.
There is a sequence of integers, which contains the equal number of even and odd numbers. Given a limited budget, you need to make maximum possible number of cuts such that each resulting segment will have the same number of odd and even integers.
Cuts separate a sequence to continuous (contiguous) segments. You may think about each cut as a break between two adjacent elements in a sequence. So after cutting each element belongs to exactly one segment. Say, [4,1,2,3,4,5,4,4,5,5] → two cuts → [4,1∣2,3,4,5∣4,4,5,5]. On each segment the number of even elements should be equal to the number of odd elements.
The cost of the cut between x and y numbers is ∣x−y∣ bitcoins. Find the maximum possible number of cuts that can be made while spending no more than B bitcoins.
有很多东西可以被“切”——树木、纸张、“绳子”。在本题中,你需要切割一个整数序列。
给定一个整数序列,其中奇数与偶数的个数相等。在预算有限的前提下,你需要进行尽可能多的切割操作,使得切割后得到的每个连续(即相邻)子段中奇数与偶数的个数均相等。
每次切割将序列划分为若干连续(contiguous)子段。你可以将每次切割理解为序列中两个相邻元素之间的断点。因此,切割完成后,每个元素恰好属于一个子段。例如:
[4,1,2,3,4,5,4,4,5,5] → 两次切割 → [4,1∣2,3,4,5∣4,4,5,5]。
要求每个子段中偶数的个数等于奇数的个数。
在数字 x 和 y 之间进行一次切割的花费为 ∣x−y∣ 比特币。求在总花费不超过 B 比特币的前提下,最多能进行多少次切割。
输入格式
First line of the input contains an integer n (2≤n≤100) and an integer B (1≤B≤100) — the number of elements in the sequence and the number of bitcoins you have.
Second line contains n integers: a1, a2, ..., an (1≤ai≤100) — elements of the sequence, which contains the equal number of even and odd numbers
输入的第一行包含一个整数 n(2≤n≤100)和一个整数 B(1≤B≤100)——分别表示序列中元素的个数以及你拥有的比特币数量。
第二行包含 n 个整数:a1, a2, ..., an(1≤ai≤100)——序列的元素,该序列中偶数与奇数的个数相等。
输出格式
Print the maximum possible number of cuts which can be made while spending no more than B bitcoins.
输出在花费不超过 B 比特币的前提下,最多可以进行的切割次数。
输入输出样例
输入#1
6 4 1 2 5 10 15 20
输出#1
1
输入#2
4 10 1 3 2 4
输出#2
0
输入#3
6 100 1 2 3 4 5 6
输出#3
2
说明/提示
In the first sample the optimal answer is to split sequence between 2 and 5. Price of this cut is equal to 3 bitcoins.
In the second sample it is not possible to make even one cut even with unlimited number of bitcoins.
In the third sample the sequence should be cut between 2 and 3, and between 4 and 5. The total price of the cuts is 1+1=2 bitcoins.
在第一个样例中,最优方案是在 2 和 5 之间将序列切开。该切割的代价为 3 比特币。
在第二个样例中,即使拥有无限数量的比特币,也无法进行哪怕一次切割。
在第三个样例中,序列应在 2 和 3 之间以及 4 和 5 之间进行切割。切割的总代价为 1+1=2 比特币。
输入解题思路,AI测评打分。不知道怎么写?