Previously thought about a similar problem, not everyone is the largest and the smallest may limit the amount of money, the previous problem can be well resolved with a random number.
So the issue was brought before the idea of a pit, completely on the breakthrough on how to deal with each person's random number.
So in the interview would not solve this problem until the end of the interview myself quiet, think about it, the idea was found wrong.
I think the idea is correct: Served 6 dollars per person, so the remaining 40 dollars, then come up with a dollar each, were randomly assigned to a person, if a person reached the limit of the amount of money, then that person under second, there is no longer eligible to receive the money. And so on until the rest of the money been distributed.
Of course, optimization can be done in the actual processing interface, such as the rest of the money each randomly assigned money can be random (random to do this of course some restrictions, so as not to click on the allocation of the excess), then if someone money + the random distribution of money> upper limit of each person, then he will not be eligible to get this money.
Ye randomly assigned to achieve, first count a few people are entitled to this money, then a number, decided to give the first of several qualified people.
My idea is this, if we have a better idea, please let me know. Thank you.
