Robin Hood
InterviewTime limit3sMemory limit256 MB
Given N wealths, repeatedly take 100 from the richest person (first on ties) K times and print the final wealth, or impossible if a theft would leave someone at 0 or less.
- Level
Easy3 of 10
- Topics
- Heap, Simulation
- Solved
- No attempts yet
Problem
Elders of the village foresee a harsh winter, and Robin Hood is worried about the wellbeing of those less well off. As usual, he plans to redistribute some wealth in the kingdom by stealing from the rich. He estimates that heists will be required.
Robin Hood follows a moral codex that determines his target. He always steals from the richest person. If several people are tied for the most wealth, he picks the first one on the list. He steals 100 monetary units at a time and never steals from anybody who would be left with (or less) money after the heist.
Given the wealth of men and the number of heists , compute the amount of wealth left after heists, following the moral codex.
Input
The first line contains two space-separated integers and . The second line contains space-separated integers , the wealth of each of Robin Hood's targets.
Output
Print the amount of wealth left after the thefts. If Robin Hood cannot perform that many thefts, print impossible.