TopcoderArchiveVisit Topcoder
SRM28 Apr 2011
SRM 504.5

TheJackpotDivTwo

Problem statement, definition, constraints, and public examples.

Problem Statement

John has recently won a jackpot, but he doesn't need the money. He decided to share it with his friends instead. He knows how much money each of his friends has, and he will use this information to perform the distribution. While he still has money left, he will repeat the following steps:
  • Choose the poorest friend. If there are multiple poorest friends, choose one of them randomly.
  • Give 1 dollar to the chosen friend.
You are given an int jackpot, the number of dollars John has won, and a int[] money, where the i-th element is the number of dollars currently owned by the i-th friend. Return a int[] containing the same number of elements as money. The return value must contain the number of dollars owned by each friend after John has performed the above distribution, sorted in non-decreasing order.

Definition

Class:
TheJackpotDivTwo
Method:
find
Parameters:
int[], int
Returns:
int[]
Method signature:
int[] find(int[] money, int jackpot)
(be sure your method is public)

Constraints

  • money will contain between 1 and 47 elements, inclusive.
  • Each element of money will be between 1 and 1,000,000, inclusive.
  • jackpot will be between 1 and 1,000,000, inclusive.

Examples

  1. {1, 2, 3, 4}
    2
    Returns: {2, 3, 3, 4 }
    First, John will give one dollar to the first friend. Then he will give another dollar to the first or the second friend.
  2. {4, 7}
    1
    Returns: {5, 7 }
    Just one action here.
  3. {1}
    100
    Returns: {101 }
    Just one friend here.
  4. {21, 85, 6, 54, 70, 100, 91, 60, 71}
    15
    Returns: {21, 21, 54, 60, 70, 71, 85, 91, 100 }
Back to all problems