1782B - Going to the Cinema - CodeForces Solution


brute force greedy sortings *1000

Please click on ads to support us..

C++ Code:

#pragma warning(disable:4996)

#include <algorithm>
#include <iostream>
#include <cstring>
#include <random>
#include <vector>
#include <cstdio>
#include <queue>
#include <cmath>
#include <map>

using std::cin;
using std::cout;
using std::endl;

constexpr long long mod = 998244353;

void clear();

void init();

void solve();

int main()
{
    std::ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    init();
    int T = 0;
    for (cin >> T; T; --T)
    {
        clear();
        solve();
    }
    return 0;
}

void init()
{

}

void clear()
{

}

void solve()
{
    int n = 0;
    cin >> n;
    std::vector <int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    std::sort(a.begin(), a.end());
    int ans = a[0] != 0;

    for (int k = 0; k < n - 1; ++k) // a[0] .. a[k] , totally k + 1 people go to the cinema
    {
        ans += a[k + 1] > k + 1 && a[k] <= k;
    }

    cout << ans + (a[n - 1] < n) << endl;
}


Comments

Submit
0 Comments
More Questions

1721A - Image
1180C - Valeriy and Deque
557A - Ilya and Diplomas
1037D - Valid BFS
1144F - Graph Without Long Directed Paths
1228A - Distinct Digits
355B - Vasya and Public Transport
1230A - Dawid and Bags of Candies
1530A - Binary Decimal
1472D - Even-Odd Game
441C - Valera and Tubes
1328E - Tree Queries
265A - Colorful Stones (Simplified Edition)
296A - Yaroslav and Permutations
967B - Watering System
152A - Marks
1398A - Bad Triangle
137A - Postcards and photos
1674D - A-B-C Sort
334A - Candy Bags
855A - Tom Riddle's Diary
1417A - Copy-paste
1038A - Equality
1061A - Coins
1676E - Eating Queries
1447A - Add Candies
1721D - Maximum AND
363C - Fixing Typos
1401A - Distance and Axis
658A - Bear and Reverse Radewoosh