Sort by quality, give back the slowest
transcript
Servers have a speed and a quality. A team scores its total speed. That total is multiplied by its lowest quality. Pick at most k servers.
Sort servers by quality, highest first. The newest server sets the lowest quality. A heap keeps the speeds, slowest on top.
Three servers give a sum of thirteen. The floor is four, so the score is fifty-two. A fourth server arrives. Give back speed one. The best score stays at fifty-two for the whole list.
Choosing the k fastest ignores quality. A low quality lowers the floor for all. Fix the floor first, then take the fastest. That scores fifty-two instead of forty-four.
Totals grow large in this problem. A big team scores a hundred billion. Use sixty-four bit sums, or the total overflows.
Sort by quality, highest first. Keep the k fastest in a heap. Give back the slowest server each time the group grows. Full breakdown in the lecture.