您的位置:首页 > 其它

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  ;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: