Help me in solving BLDST problem. Is it necessary to fill all the boxes according to question?

My issue

My code

#include <bits/stdc++.h>


using namespace std;

int main() {
    int T;
    cin >> T;

    while (T--) {
        int N, M;
        cin >> N >> M;

        vector<int> balls(M);
        for (int i = 0; i < M; i++) {
            cin >> balls[i];
        }

        sort(balls.rbegin(), balls.rend()); // Sort in non-decreasing order

        int minBoxes = INT_MAX;
        int excess = 0;

        for (int i = 0; i < M; i++) {
            int diff = balls[i] - M;
            excess += diff;

            if (excess < 0) {
                excess = 0;
            }

            int boxes = (excess + M - 1) / M; // Calculate the number of boxes with M balls

            minBoxes = min(minBoxes, boxes + i + 1); // Update the minimum number of boxes
        }

        cout << minBoxes << endl;
    }

    return 0;
}

Problem Link: BLDST Problem - CodeChef

@hackeryn
No its not necessary to fill all the boxes
all u have to do is to fill the boxes in such a way that the box contains different color balls and the count of box having M balls should be minimum