forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTheJackpotDivOne.html
More file actions
19 lines (18 loc) · 4.34 KB
/
Copy pathTheJackpotDivOne.html
File metadata and controls
19 lines (18 loc) · 4.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<html><body bgcolor="#000000" text="#ffffff"><table><tr><td colspan="2"><h3>Problem Statement</h3></td></tr><tr><td>    </td><td><p>
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:
<ul>
<li>Calculate the average amount of money each of his friends has. Call this value A.</li>
<li>Choose the poorest friend. If there are multiple poorest friends, choose one of them randomly. P is the amount of money owned by the chosen friend.</li>
<li>Determine the value of X, where X is the smallest integer such that P + X is strictly greater than A.</li>
<li>If John has at least X dollars, give X dollars to the chosen friend. Otherwise, give all the remaining money to that friend.</li>
</ul>
</p>
<p>
You are given a long long <b>jackpot</b>, the number of dollars John has won, and a vector<long long> <b>money</b>, where the i-th element is the number of dollars currently owned by the i-th friend.
Return a vector<long long> 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.
</p>
</td></tr><tr><td colspan="2"><h3>Definition</h3></td></tr><tr><td>    </td><td><table><tr><td>Class:</td><td>TheJackpotDivOne</td></tr><tr><td>Method:</td><td>find</td></tr><tr><td>Parameters:</td><td>vector<long long>, long long</td></tr><tr><td>Returns:</td><td>vector<long long></td></tr><tr><td>Method signature:</td><td>vector<long long> find(vector<long long> money, long long jackpot)</td></tr><tr><td colspan="2">(be sure your method is public)</td></tr></table></td></tr><tr><td>    </td></tr><tr><td></td></tr><tr><td colspan="2"><h3>Constraints</h3></td></tr><tr><td align="center" valign="top">-</td><td><b>money</b> will contain between 1 and 47 elements, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td>Each element of <b>money</b> will be between 1 and 10^18, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td><b>jackpot</b> will be between 1 and 10^18, inclusive.</td></tr><tr><td colspan="2"><h3>Examples</h3></td></tr><tr><td align="center" nowrap="true">0)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>{1, 2, 3, 4}</pre></td></tr><tr><td><pre>2</pre></td></tr></table></td></tr><tr><td><pre>Returns: {2, 3, 3, 4 }</pre></td></tr><tr><td><table><tr><td colspan="2">The average is 2.5. John will give all his money to the first friend with a single action.</td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">1)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>{4}</pre></td></tr><tr><td><pre>7</pre></td></tr></table></td></tr><tr><td><pre>Returns: {11 }</pre></td></tr><tr><td><table><tr><td colspan="2">There is just one friend here.</td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">2)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>{4, 44, 7, 77}</pre></td></tr><tr><td><pre>47</pre></td></tr></table></td></tr><tr><td><pre>Returns: {24, 34, 44, 77 }</pre></td></tr><tr><td><table><tr><td colspan="2">Iniitially, the average is 33, so John will give 30 dollars to the first friend, who will then have 34 dollars total. The average then becomes 40.5, and John will give the rest of the money to the third friend.</td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">3)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>{4, 10, 8, 3, 6, 5, 8, 3, 7, 5}</pre></td></tr><tr><td><pre>1000</pre></td></tr></table></td></tr><tr><td><pre>Returns: {105, 106, 106, 106, 106, 106, 106, 106, 106, 106 }</pre></td></tr><tr><td></td></tr></table></td></tr></table><p>This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved. </p></body></html>