A11772 | Cutting
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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]$ $\to$ two cuts $\to$ $[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.
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]$ $\to$ two cuts $\to$ $[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.
输入格式
First line of the input contains an integer $n$ ( $2 \le n \le 100$ ) and an integer $B$ ( $1 \le B \le 100$ ) — the number of elements in the sequence and the number of bitcoins you have.
Second line contains $n$ integers: $a_1$ , $a_2$ , ..., $a_n$ ( $1 \le a_i \le 100$ ) — elements of the sequence, which contains the equal number of even and odd numbers
Second line contains $n$ integers: $a_1$ , $a_2$ , ..., $a_n$ ( $1 \le a_i \le 100$ ) — elements of the sequence, which contains the equal number of even and odd numbers
输出格式
Print the maximum possible number of cuts which can be made while spending no more than $B$ bitcoins.
输入输出样例
输入 #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.
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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted