Connection Status:
Competition Arena > TheJackpotDivTwo
SRM 504.5 · 2011-04-28 · by Vasyl[alphacom] · Simulation
Class Name: TheJackpotDivTwo
Return Type: int[]
Method Name: find
Arg Types: (vector<int>, int)
Problem Statement

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.

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
0)
{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.

1)
{4, 7}
1
Returns: {5, 7 }

Just one action here.

2)
{1}
100
Returns: {101 }

Just one friend here.

3)
{21, 85, 6, 54, 70, 100, 91, 60, 71}
15
Returns: {21, 21, 54, 60, 70, 71, 85, 91, 100 }
4)
{68, 30, 5, 66, 69, 25, 58}
55
Returns: {38, 38, 39, 58, 66, 68, 69 }

Submissions are judged against all 95 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class TheJackpotDivTwo with a public method vector<int> find(vector<int> money, int jackpot) · 95 test cases · 2 s / 256 MB per case

Submitting as anonymous