Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "bits/stdc++.h"
- using namespace std;
- int main(){
- int n,l;cin>>n>>l;
- vector<int> v;
- for(int i=0;i<n;i++){
- int x;cin>>x;
- v.push_back(x);
- }
- sort(v.begin(), v.end());
- reverse(v.begin(),v.end());
- int L=1;//L doesnt work
- while(true){
- if(v[L-1]>=L){
- L++;
- } else break;
- }
- int cnt=0;
- for(int i=0;i<L;i++){
- if(v[i]<L){
- if(v[i]==L-1)cnt++;
- else{
- cout<<L-1<<endl;
- return 0;
- }
- }
- }
- if(cnt<=l)cout<<L<<endl;
- else cout<<L-1<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement