Company: Titan
Difficulty: medium
A queue of n monsters stands in a fixed order. The i -th monster in the queue has power a[i] . You command m heroes. The j -th hero is described by two numbers: p[j] — the hero's power : this hero can defeat a monster only if p[j] >= (that monster's power) . s[j] — the hero's endurance : this hero can defeat at most s[j] monsters in a single day. Each day exactly one hero is sent out (any hero, and the same hero may be sent on many different days). The chosen hero starts at the first monster that is still alive and fights the monsters one after another in queue order. The hero's day ends as soon as any of the following happens: the hero has already defeated s[j] monsters that day, or the next monster alive has power strictly greater than p[j] , or no monsters are left. A hero may also defeat fewer monsters than his endurance allows — you decide when to stop him. Determine the minimum number of days needed to defeat all n monsters, or report that it is impossible.