Submission

Status:
[PPPPPPPPPPPP]

Score: 100

User: mydKN

Problemset: 01.H-index

Language: cpp

Time: 0.394 second

Submitted On: 2025-03-31 13:33:21

#include<bits/stdc++.h>

using namespace std;

bool ok(int mid, vector<int> &vec){
	auto it = lower_bound(vec.begin(), vec.end(), mid) - vec.begin();
	if(vec.size() - it >= mid) return 1;
	return 0;
}

void mains(){
	int n;
	cin >> n;
	vector<int> vec(n);
	for(auto &e : vec){
		cin >> e;
	}
	sort(vec.begin(), vec.end());
	int l = 0, r = 1e9;
	while(l < r){
		int m = (l + r) / 2;
		if(ok(m, vec)){
			l = m + 1;
		}
		else{
			r = m;
		}
		// cout << l << " " << m << " " << r << "\n";
	}
	// cout << "\n";
	cout << l-1 << "\n";
}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int t = 1;
	while(t--) mains();
}

/*
5
1 100 3 2 1
12
2 5 3 8 3 5 8 7 6 0 4 3
20
3 5 2 7 10 9 10 7 9 10 7 5 4 0 4 12 300 7 12 5

2
5
8
*/