Collectors Problem

The Bat club controls Gotham City. They decided to bring equality to the city (Of course, with some profits in their pocket). There are NNN people in the city. The ithi^{th}ith person has DiD_iDi​ dollars in his/her bank account. To bring equality in the bank balance of the people of Gotham City, the Bat club appointed a collector. The Bat club has offered MMM packages to the collector. The ithi^{th}ith package has a value of PiP_iPi​ and the collector has to pay SiS_iSi​ dollars for the package. The collector has to choose a package. If the collector chooses the ithi^{th}ith package, he has to make everyone’s bank balance equal to PiP_iPi​ dollars. If a person has more than PiP_iPi​ dollars in his/her bank account, the collector will take the rest of the money leaving PiP_iPi​ dollars in his/her account. If a person has less than PiP_iPi​ dollars, the collector will add the necessary amount of dollars to make the bank balance equal to PiP_iPi​ dollars.


This is a companion discussion topic for the original entry at https://toph.co/p/collectors-problem