Please help me debug my code for CRFTEST

I have a question for CFRTEST. I keep getting a WA. Here’s my code:

#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {

    int cases;
    cin >> cases;

    for (int case_no = 0; case_no < cases; case_no++) {

        int friends;
        cin >> friends;

        int deadlines[friends];

        for (int i = 0; i < friends; i++) {
            cin >> deadlines[i];
        }

        sort(deadlines, deadlines + friends);

        int count = 0;
        int filled_till = 0;

        for (int i = 0; i < friends; i++) {
            if (deadlines[i] > filled_till) {
                filled_till++;
                count++;
            }
        }

        cout << count << endl;

    }

    return 0;

}

Could anybody please help me recognize the flaw? It works well on all the testcases I’ve tried.

Hey dear!

Your code fails for this test case-

Input-
1
5
1 5 5 9 9
Output
5
Expected Output
3

What you should do is to remove all duplicate elements. Your “Filled till” is being wrongly updated. In this test case, After giving party to 1, your filled in/deadline is 1, which is good. But after giving party to 5, filled in becomes “2” instead of “5”. This si causing you problem.

Instead of doing all this,you can insert all the elements in to a set and finally print n-set.size()

3 Likes

Programming language is known by only who know the correct knowledge and deep knowledge in that field.Kerala holidayso package

//