Cutting Codeforces Round #493 (Div. 2)
Cutting
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.
Input
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
Output
Print the maximum possible number of cuts which can be made while spending no more than Bbitcoins.
Input
6 4
1 2 5 10 15 20
Output
1
Input
4 10
1 3 2 4
Output
0
Input
6 100
1 2 3 4 5 6
Output
2
123456789101112131415161718192021222324
一道很簡單的暴力題,但是一直沒有抓住關鍵。
問題的性質:每個切點之間沒有關系,即某個切點切還是不切不影響其他的切點,需要看出來他們之間的不關聯性。
附ac碼
總結
以上是生活随笔為你收集整理的Cutting Codeforces Round #493 (Div. 2)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: lol德莱文接斧头技巧
- 下一篇: 血精症导致不孕不育!