Source Code
/*
     Author: Asmaa Raafat
*/
/////////////////////////////"THINK TWICE... CODE ONCE"/////////////////////////////////.
#include <bits/stdc++.h>
#define ll long long
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int main()
{
    #ifndef ONLINE_JUDGE
    //freopen("fight.txt", "rt", stdin);
    #endif
    fast;
    int n, k;
    cin>>n>>k;
    int arr[n];
    int cnt=0;
    for(int i=0; i<n; i++)
    {
        cin>>arr[i];
    }
    sort(arr, arr+n);
    for(int i=n-1; i>=0; i--)
    {
        if(arr[i] <= k)
        {
            cnt ++;
            k--;
        }
    }
    cout<<abs(n-cnt);
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
*/
Copy
Cutting Trees asmaa_raafat
GNU G++17
13 ms
448 KB
Wrong Answer