FZU2216

来源:互联网 发布:windows串口编程实例 编辑:程序博客网 时间:2024/04/26 12:26
#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  ;}

0 0