The only thing you have overlooked is the constraints of the program.
Eventhough your scan function for number of games from 1 to 1000 is correct.
When you use the same scan function for the scores of each game whose constraint ranges from 0 to 10⁸.
You have considered the upper bound.
But You have overlooked the lower bound whose value begins from 0.
Change the if statement in the scan function to :
if(k<=z && k>=0)
This will provide the desired result and clear all the test cases.
You can send me your solutions or your ideas for any coding challenge. I would be thrilled to read them. ;)
I will clear your doubts within a day or two.