FZU2216
2016-04-19 13:39
134 查看
#include <iostream> #include <string> #include <string.h> #include <vector> #include <stdio.h> #include <algorithm> #include <map> #include <math.h> typedef long long LL ; std::vector<int> stone ; int main(){ int t , limit , x , n , m , L , R , used , unUsed ; scanf("%d" , &t) ; while(t--){ limit = 0 ; stone.clear() ; scanf("%d%d" , &n , &m) ; for(int i = 0 ; i < n ; i++){ scanf("%d" , &x) ; if(x) stone.push_back(x) ; else limit++ ; } std::sort(stone.begin() , stone.end()) ; stone.erase( std::unique(stone.begin() , stone.end()) , stone.end() ) ; int res = std::min(m , limit) ; for(L = 0 , R = 0 ; L < stone.size() ; L++){ while(R < stone.size() && stone[R] - stone[L] + 1 <= R - L + 1 + limit) R++ ; R-- ; used = (stone[R] - stone[L] + 1 ) - ( R - L + 1 ) ; unUsed = limit - used ; res = std::max(res , stone[R] - stone[L] + 1 + std::min(unUsed , m - (stone[R] - stone[L] + 1))) ; } std::cout<< res << std::endl ; } return 0 ; }
相关文章推荐
- Paint及Canvas的简单应用
- java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
- java WebService CXF Spring 自定义拦截器 附实例源码
- ios 打印 结构体
- 去掉Scrollview滑动顶部和顶部阴影
- Python相对导入导致SystemError的解决方案(译)
- Hash时取模为什么要模质数
- mysql 10060远程不能访问
- PHP数据对象映射模式
- HTML5 --Web Workers
- UIGestureRecognizer介绍
- ZZULIOJ-1874: 蛤玮学计网
- Pixhawk之姿态解算篇(4)_补充篇
- 部分和问题
- 基于MT7688模块的开发笔记1——关于Ubuntu版本
- jQuery页面滚动右侧浮动导航切换
- JS计算时间差值
- Android开发中,那些让你相见恨晚的方法、类或接口
- 8款效果精美的 jQuery 加载动画和进度条插件
- 团队冲刺第一阶段个人工作总结1