TopcoderArchiveVisit Topcoder
Archive
Algorithm problem

HighestScore

Problem statement, definition, constraints, and public examples.

Problem Statement

*** WARNING: Do not leave the competition room while you are competing. If you have a question, use "admins: question" in the chat area. ***

You have just recieved a new game for your arcade, which has a high score list with five slots available. Frequently there will be some arcade master out there who has already played the game a hundred thousand times even though the game is brand-new, and will rack up all the high scores to unimaginable levels, making it impossible for anyone else to get on the list. Therefore management orders you to clear the scores if the score required to get onto the list of five highest scores is too high. You will be given a list of scores generated by people throughout the day, in the order that they were generated. You will also be given a limit to how high the entry score into the high-score list can get before you are ordered to reset the list of scores. You will return the number of times you had to reset the high score list that day.

In more detail, the high score list will display the top 5 scores since the last time the score list was cleared. If there have not been 5 high scores since the last time the list was cleared, then any score will make it on to the top 5 list. If there are 5 scores on the score list, and the lowest score on the score list is ever greater than limit, then the list must be reset.

Definition

Class:
HighestScore
Method:
bestFive
Parameters:
int[], int
Returns:
int
Method signature:
int bestFive(int[] scores, int limit)
(be sure your method is public)

Notes

  • To make things simpler, the limit will not be an element of scores, so you need not worry about whether the limit is inclusive or exclusive, or what happens if you get the lowest score on the top 5 list.
  • At the beginning of the day and after every time the scores are reset, there are no high scores on the list.

Constraints

  • scores will be a int[] and will contain between 1 and 50 elements, inclusive.
  • Every element in scores will be an int between 0 and 1000000000, inclusive.
  • Every element in scores will be unique.
  • limit will be an int between 10000 and 1000000 inclusive.
  • limit will not be an element of scores.

Examples

  1. {13000,17000,16000,15000,14000}
    11000
    Returns: 1
    Upon the fifth game, the high score list will have a minimum of 13000 to get onto the list. This is above the limit, and thus the scores will have to be cleared. If these are the only games played this day on this machine, then the scores will have been reset once.
  2. {13000,17000,16000,15000,14000}
    13999
    Returns: 0
    Same scores, but different limit. Notice that since only four of the scores are over the limit that the score to beat in order to enter the list must be less than the limit, so the machine doesn't need to be reset.
  3. {1000000,2000000,3000000,4000000,5000000,6000000,7000000,8000000,9000000,10000000,11000000}
    10000
    Returns: 2
  4. {230000,450000,980000,170000}
    125000
    Returns: 0
    All of the high scores will start below the limit when reset, so there is still a slot available for someone to score under the limit yet make it into the high score list.
  5. {1000000000,999999999,999999998,999999997,999999996,
     999999995,999999994,999999993,999999992,999999}
    1000000
    Returns: 1
Back to all problems