My issue
My code
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int minimumBoxes(int N, int M, vector<int>& ballColors) {
int totalColors = 0;
int totalBalls = 0;
for (int i = 0; i < M; i++) {
totalColors += (ballColors[i] > 0);
totalBalls += ballColors[i];
}
return (totalBalls >= M && totalColors >= M) ? M : -1;
}
int main() {
int T;
cin >> T;
while (T--) {
int N, M;
cin >> N >> M;
vector<int> ballColors(M);
for (int i = 0; i < M; i++) {
cin >> ballColors[i];
}
int minBoxes = minimumBoxes(N, M, ballColors);
cout << minBoxes << endl;
}
return 0;
}
Problem Link: BLDST Problem - CodeChef