Skip to content

Instantly share code, notes, and snippets.

@surinoel
Created October 5, 2019 16:09
Show Gist options
  • Save surinoel/b0fa4fe6a069a83fcf1c8d0ee37ff14d to your computer and use it in GitHub Desktop.
Save surinoel/b0fa4fe6a069a83fcf1c8d0ee37ff14d to your computer and use it in GitHub Desktop.
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
sort(v.begin(), v.end(), greater<int>());
int maxv = v[0] + 1;
int ans = 1;
for (int i = 1; i < v.size(); i++) {
if (maxv > v[i] + n) {
break;
}
maxv = max(maxv, v[i] + i + 1);
ans += 1;
}
cout << ans << '\n';
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment