Well, looks like there’s a lot you can improve on.
Ok, now let’s look at the (possible)errors:
while(test-->0) : maybe it’s going through all the test cases, or maybe it’s just leaving out the last test case. I haven’t tried it. What I did was
std::vector<int> theNums(N); : since the range for the numbers present in the list is not mentioned, the numbers can be of type long long, long, or just short. The safest way is
std::vector<long long> theNums(N); .
theNums.erase(...), you should be sorting the list - so that you can remove the D greatest numbers in the list. I think you were going to use the
sort(...) function for that, for which you included the
<algorithm> file, but you forgot to add the function later.
Lastly(but it’s quite important for coding practices in C++14), just write
using namespace std; after including all the required header files - I had a hard time going through the same
std:: multiple times.
You can go through this link for understanding the solution: https://www.codechef.com/viewsolution/24028722