My issue
It is not passing hidden test cases
My approach :
I have sorted both array, reversed it, took there first four players (as they are the highest), erased them from the array.
concatenate the remaining array, sorted it, reversed it and then took the remaining 3 players
added all of their skills and printed it.
The visible test cases are passing but the hidden are not, please help me find the error
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> arr_N(N);
vector<int> arr_M(M);
for (int &i : arr_N)
cin >> i;
for (int &i : arr_M)
cin >> i;
if (M < 4 || N < 4) {
cout << "-1" << endl;
continue;
}
sort(arr_N.begin(), arr_N.end());
sort(arr_M.begin(), arr_M.end());
reverse(arr_N.begin(), arr_N.end());
reverse(arr_M.begin(), arr_M.end());
int sum = 0;
for (int i = 0; i < 4; i++) {
sum += arr_N[i];
sum += arr_M[i];
}
arr_N.erase(arr_N.begin(), arr_N.begin() + 4);
arr_M.erase(arr_M.begin(), arr_M.begin() + 4);
arr_N.insert(arr_N.end(), arr_M.begin(), arr_M.end());
sort(arr_N.begin(), arr_N.end());
reverse(arr_N.begin(), arr_N.end());
for (int i = 0; i < 3; i++) {
sum += arr_N[i];
}
cout << sum << endl;
}
}
Problem Link: GAME 11 Practice Coding Problem - CodeChef