Advertisement
ec1117

Untitled

Mar 20th, 2022
1,014
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include "bits/stdc++.h"
  2.  
  3. using namespace std;
  4.  
  5. int main(){
  6.     int n,l;cin>>n>>l;
  7.     vector<int> v;
  8.     for(int i=0;i<n;i++){
  9.         int x;cin>>x;
  10.         v.push_back(x);
  11.     }
  12.     sort(v.begin(), v.end());
  13.     reverse(v.begin(),v.end());
  14.    
  15.     int L=1;//L doesnt work
  16.     while(true){
  17.         if(v[L-1]>=L){
  18.             L++;
  19.         } else break;
  20.     }
  21.  
  22.     int cnt=0;
  23.     for(int i=0;i<L;i++){
  24.         if(v[i]<L){
  25.             if(v[i]==L-1)cnt++;
  26.             else{
  27.                 cout<<L-1<<endl;
  28.                 return 0;
  29.             }
  30.         }
  31.     }
  32.     if(cnt<=l)cout<<L<<endl;
  33.     else cout<<L-1<<endl;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement