Children and Gift Boxes
InterviewTime limit1sMemory limit1024 MB
Given N boxes of gifts and M children with desired amounts in a fixed order, decide if each child in turn can take their amount from the currently fullest box.
- Level
Medium6 of 10
- Topics
- Greedy, Heap, Simulation, Sorting
- Solved
- No attempts yet
Problem
Sanghun has gift boxes. Each gift box has the number of gifts it currently holds written on it.
There are children who will receive gifts. Each child is assigned a distinct number from to .
One at a time, from child to child , each child takes as many gifts as they want from the box that currently holds the most gifts. A child may take from a box that someone has already taken gifts from.
If a box holds fewer gifts than the child wants, the child cannot take any gifts and is disappointed.
Sanghun wants to know whether every child can take the gifts they want without anyone being disappointed.
Input
The first line gives the number of gift boxes and the number of children , separated by a space. ()
The second line gives the number of gifts in each gift box, , separated by spaces. ()
The third line gives the number of gifts each child wants, , in order of the children's numbers, separated by spaces. ()
Output
Print if every child can take the gifts they want without anyone being disappointed, and otherwise.