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码

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; int a[105]; //记录原数组
int b[105]; //记录奇数个数的前缀和
int c[105]; //记录所有的切点
int n,s,tmp;
int cnt=0,ans; int main()
{
while(~scanf("%d%d",&n,&s))
{
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));
ans=0;
cnt=0;
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
b[i]=a[i]%2+b[i-1];
}
if(n%2==0 && b[n]==n/2) //如果奇数个数字或者整个数列中奇数和偶数的个数不相等显然切不成
{
for(int i=2;i<n;i+=2)
{
if(b[i]==i/2)
c[cnt++]=abs(a[i+1]-a[i]);
}
sort(c,c+cnt);
tmp=0;
for(int i=0;i<cnt;i++)
{
if(tmp+c[i]<=s)
{
tmp+=c[i];
ans++;
}
else
{
break;
}
}
}
printf("%d\n",ans);
}
return 0;
}

Cutting Codeforces Round #493 (Div. 2)的更多相关文章

  1. 【Codeforces Round #493 (Div. 2) B】Cutting

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 显然只有在前i个位置奇数偶数出现次数都相同的地方才能切. (且不管前面怎么切,这里都能切的. 那么就相当于有n个物品,每个物品的代价 ...

  2. Codeforces Round #493 (Div. 2) B. Cutting 前缀和优化_动归水题

    不解释,题目过水 Code: #include<cstdio> #include<cmath> #include<algorithm> using namespac ...

  3. Codeforces Round #493 (Div 2) (A~E)

    目录 Codeforces 998 A.Balloons B.Cutting C.Convert to Ones D.Roman Digits E.Sky Full of Stars(容斥 计数) C ...

  4. Codeforces Round #493 (Div. 2)

    C - Convert to Ones 给你一个01串 x是反转任意子串的代价 y是将子串全部取相反的代价 问全部变成1的最小代价 两种可能 一种把1全部放到一边 然后把剩下的0变成1  要么把所有的 ...

  5. Codeforces Round #493 (Div. 1)

    A. /* 发现每次反转或者消除都会减少一段0 当0只有一段时只能消除 这样判断一下就行 */ #include<cstdio> #include<algorithm> #in ...

  6. Codeforces Round #493 (Div. 2)D. Roman Digits 第一道打表找规律题目

    D. Roman Digits time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  7. Codeforces Round #493 (Div. 2) A. Balloons 贪心水题

    由于是输出任意一组解,可以将价值从小到大进行排序,第一个人只选第一个,第二个人选其余的.再比较一下第一个人选的元素和第二个人所选元素和是否相等即可.由于已将所有元素价值从小到大排过序,这样可以保证在有 ...

  8. Codeforces Round #493 (Div. 1) B. Roman Digits 打表找规律

    题意: 我们在研究罗马数字.罗马数字只有4个字符,I,V,X,L分别代表1,5,10,100.一个罗马数字的值为该数字包含的字符代表数字的和,而与字符的顺序无关.例如XXXV=35,IXI=12. 现 ...

  9. Codeforces Round #493 (Div. 2) C. Convert to Ones 乱搞_构造_好题

    题意: 给你一个长度为 nnn 的 010101串 ,你有两种操作: 1.将一个子串翻转,花费 XXX 2.将一个子串中的0变成1,1变成0,花费 YYY 求你将这个01串变成全是1的串的最少花费. ...

随机推荐

  1. java 数组复制

    http://www.cnblogs.com/zhengbin/p/5671403.html http://www.cnblogs.com/jjdcxy/p/5870524.html Java数组拷贝 ...

  2. tp5分页后数据处理

  3. Intsall The Nessus in you kali linux

    1.first you shold download the nessus on the web station the nessus download site url:  https://www. ...

  4. python selenium Chrome模拟手机浏览器

    在做移动端页面测试时可以利用Chrome mobile emulation 辅助完成页面的适配问题,但是目前手机市场上的型号居多我们也没有办法通过人工的模式一一的去适配,所以这里考虑到通过自动化的模式 ...

  5. Python调用selenium

    import time from selenium import webdriver from selenium.webdriver.common.touch_actions import Touch ...

  6. Cesium 动态更换模型贴图方法

    参考资料 github 讨论地址 示例代码地址 示例代码 var viewer = new Cesium.Viewer('cesiumContainer'); var scene = viewer.s ...

  7. 3.基于梯度的攻击——PGD

    PGD攻击原论文地址——https://arxiv.org/pdf/1706.06083.pdf 1.PGD攻击的原理 PGD(Project Gradient Descent)攻击是一种迭代攻击,可 ...

  8. redis学习(八)——redis应用场景

    毫无疑问,Redis开创了一种新的数据存储思路,使用Redis,我们不用在面对功能单调的数据库时,把精力放在如何把大象放进冰箱这样的问题上,而是利用Redis灵活多变的数据结构和数据操作,为不同的大象 ...

  9. ArrayList Vector

    100000条数据时:测了4次,分别是9ms/13ms:8ms/6ms:8ms/6ms:8ms/6ms[其中/前为ArrayList数据,/后为Vector数据]1000000条数据时:测了4次,分别 ...

  10. java线程之二(synchronize和volatile方法)

    要说明线程同步问题首先要说明Java线程的两个特性,可见性和有序性.多个线程之间是不能直接传递数据交互的,它们之间的交互只能通过共享变量来实现.拿上篇博文中的例子来说明,在多个线程之间共享了Count ...