Submission
Status:
[PPPPPPPPPPPP]
Score: 100
User: pppppppppppp
Problemset: 01.H-index
Language: cpp
Time: 0.276 second
Submitted On: 2025-04-17 09:01:40
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
// bucket[i] = number of papers cited exactly i times (for i<N),
// bucket[N] = number of papers cited >= N times
vector<int> bucket(N+1, 0);
for (int i = 0; i < N; i++) {
long long c;
cin >> c;
if (c > N)
bucket[N]++;
else
bucket[c]++;
}
// Starting from the largest possible h (N) down to 0,
// keep a running total of how many papers have ≥ i citations.
int running = 0;
for (int h = N; h >= 0; h--) {
running += bucket[h];
if (running >= h) {
cout << h;
return 0;
}
}
// (We will always hit the return inside the loop at h=0.)
return 0;
}