There are N (1 ≤ N ≤ 105) colored blocks (numbered 1 to N from left to right) which are lined up in a row. And the i-th block's color is Ci (1 ≤ Ci ≤ 109). Now you can remove at most K (0 ≤ KN) blocks, then rearrange the blocks by their index from left to right. Please figure out the length of the largest consecutive blocks with the same color in the new blocks created by doing this.

For example, one sequence is {1 1 1 2 2 3 2 2} and K=1. We can remove the 6-th block, then we will get sequence {1 1 1 2 2 2 2}. The length of the largest consecutive blocks with the same color is 4.

Input

Input will consist of multiple test cases and each case will consist of two lines. For each test case the program has to read the integers N and K, separated by a blank, from the first line. The color of the blocks will be given in the second line of the test case, separated by a blank. The i-th integer means Ci.

Output

Please output the corresponding length of the largest consecutive blocks, one line for one case.

Sample Input

8 1
1 1 1 2 2 3 2 2

Sample Output

4

题目大意:给一串连续的数字,最多可以删除k个,求相同数字连续个数最大的值。
可以离散化一下把相同数字的下标Push到同一个容器中,再去每个容器中暴力求最大值。
 #include <iostream>
#include <cstdio>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std; const int maxn=;
vector<int> v[maxn];
int f[maxn],X;
int test[maxn]; int Max(int a,int b){ return a>b?a:b;} int fun(int a,int b)
{
int i,j,len=v[a].size();
for(i=len;i>=;i--)
{
for(j=;j<=len-i;j++)
{
if(v[a][i+j-]-v[a][j]+-i<=b)
return i;
}
}
return ;
} int main()
{
int n,k,i,max;
while(~scanf("%d %d",&n,&k))
{
for(i=;i<n;i++) v[i].clear();
for(i=;i<n;i++)
{
scanf("%d",f+i);
test[i]=f[i];
}
sort(test,test+n);
X=unique(test,test+n)-test;
for(i=;i<n;i++)
{
int t=lower_bound(test,test+X,f[i])-test;
v[t].push_back(i);
}
max=;
for(i=;i<X;i++)
{
max=Max(max,fun(i,k));
}
printf("%d\n",max);
}
return ;
}
												

zoj 3790 Consecutive Blocks 离散化+二分的更多相关文章

  1. ZOJ 3790 Consecutive Blocks (离散化 + 暴力)

    题目链接 虽然是一道暴力的题目,但是思路不好想.刚开始还超时,剪枝了以后1200ms,不知道为什么还是这么慢. 题意:给你n个点,每个点有一种颜色ci,给你至多k次删除操作,每次删除一个点,问最多k次 ...

  2. ZOJ 3790 Consecutive Blocks 模拟题

    problemCode=3790">Consecutive Blocks 先离散一下,然后模拟,把一种颜色i所在的位置都放入G[i]中.然后枚举一下终点位置,滑动窗体使得起点和终点间花 ...

  3. ZOJ 3790 Consecutive Blocks

    大致题意就是给你一个数列,让你最多移除K个数字,使得连续的相同数字的长度最大,并求出最大长度. 我们将此序列按颜色排序,颜色相同的话按位置排序,那么排完序之后颜色相同的blocks就在一起,只是他们的 ...

  4. [Codeforces 1199C]MP3(离散化+二分答案)

    [Codeforces 1199C]MP3(离散化+二分答案) 题面 给出一个长度为n的序列\(a_i\)和常数I,定义一次操作[l,r]可以把序列中<l的数全部变成l,>r的数全部变成r ...

  5. POJ2391 Floyd+离散化+二分+DINIC

    题意:       有n个猪圈,每个猪圈里面都有一定数量的猪(可能大于当前猪圈的数量),每个猪圈都有自己的容量,猪圈与猪圈之间给出了距离,然后突然下雨了,问多久之后所有的猪都能进圈. 思路:     ...

  6. zoj 3299(区间改动+离散化)

    题意:有n个由小木块组成的长条木块要掉下来.给出木块的左右区间,然后有给了m个木板的左右区间和高度用来接住木块,由于木块是由小木块接触组成的,也就是木板能够接住一部分的木块.剩下的会继续掉落,问最后每 ...

  7. zoj 2362 Beloved Sons【二分匹配】

    题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2361 来源:http://acm.hust.edu.cn/vjudg ...

  8. hdu 4400 离散化+二分+BFS(暴搜剪枝还超时的时候可以借鉴一下)

    Mines Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

  9. ZOJ 1654 Place the Robots (二分匹配 )

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=654 Robert is a famous engineer. One ...

随机推荐

  1. CPP-基础:extern"C"

    简介:extern "C" 包含双重含义,从字面上即可得到:首先,被它修饰的目标是“extern”的:其次,被它修饰的目标是“C”的.让我们来详细解读这两重含义. 含义: 1.被e ...

  2. ORACLE的SQL JOIN方式大全

    ORACLE的SQL JOIN方式大全 在ORACLE数据库中,表与表之间的SQL JOIN方式有多种(不仅表与表,还可以表与视图.物化视图等联结),官方的解释如下所示 A join is a que ...

  3. lua在linxu和windows系统下的遍历目录的方法

    在windows下遍历目录使用lfs库:例如遍历整个目录下的所有文件 local lfs = require "lfs" function findPathName(path)  ...

  4. jq封装插件,简单dome

    (function($) { $.fn.extend({ bold: function() { this.css({ fontWeight: "bold", color: 'red ...

  5. LeetCode之Weekly Contest 92

    第一题:转置矩阵 问题: 给定一个矩阵 A, 返回 A 的转置矩阵. 矩阵的转置是指将矩阵的主对角线翻转,交换矩阵的行索引与列索引. 示例 1: 输入:[[1,2,3],[4,5,6],[7,8,9] ...

  6. Flask初学者:Jinja2模板

    Python的Jinja2模板,其实就是在HTML文档中使用控制语句和表达语句替换HTML文档中的变量来控制HTML的显示格式,Python的Jinja2模板可以更加灵活和方便的控制HTML的显示,而 ...

  7. HDU:1251-统计难题(字典树模板,动态建树,静态建树)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1251 统计难题 Time Limit: 4000/2000 MS (Java/Others) Memor ...

  8. HUD:4405-Aeroplane chess(期望飞行棋)

    Aeroplane chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Pro ...

  9. hdu 6354

    Problem Description Edward is a worker for Aluminum Cyclic Machinery. His work is operating mechanic ...

  10. selenium2设置浏览器窗口

    1.窗口最大化 //设置窗口最大化driver.manage().window().maximize(); 2.指定设置窗口大小 //指定呀设置窗口的宽度为:800,高度为600Dimension d ...