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) {

        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-

1 5 5 9 9
Expected Output

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()


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