Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <assert.h>
- #include <bits/stdc++.h>
- using namespace std;
- #define dbg(...) logger(#__VA_ARGS__, __VA_ARGS__)
- template <typename... Args> void logger(string vars, Args &&... values)
- {
- cerr << vars << " = ";
- string delim = "";
- (..., (cerr << delim << values, delim = ", "));
- cerr << endl;
- }
- template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
- using ll = long long;
- using pii = pair<int, int>;
- int n;
- ll a[300003];
- int main(int argc, char **argv)
- {
- scanf("%d", &n);
- for (int i = 1; i <= n; ++i)
- scanf("%lld", a + i);
- sort(a + 1, a + 1 + n);
- int ans = 0;
- int expect = 1;
- for (int lb = 1, ub = n; lb <= ub; ++lb) {
- if (a[lb] == expect) {
- ++expect;
- ++ans;
- } else {
- while (lb + 1 <= ub) {
- ub -= 2;
- ++expect;
- ++ans;
- if (lb <= ub && a[lb] == expect) {
- ++expect;
- ++ans;
- break;
- }
- }
- }
- }
- printf("%d\n", ans);
- return 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement