Picky Children and Gift Boxes
InterviewTime limit1sMemory limit1024 MB
Each child in order takes w_i gifts from the box ranked b_i-th largest by current count; decide if every child can succeed.
- Level
Medium6 of 10
- Topics
- Sorting, Greedy, Array, Implementation
- Solved
- No attempts yet
Problem
Sanghun has gift boxes. Each gift box is labeled with the number of gifts it currently contains.
There are children who will receive gifts. Each child is assigned a distinct number from to .
Children through , one at a time, each take as many gifts as they want from the gift box that has the -th most gifts, where is that child's thoughtfulness. For example, if a child's thoughtfulness is , they take from the box with the third most gifts. A child may take from a box that someone has already taken gifts from.
However, if the box contains 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. ()
The fourth line gives each child's thoughtfulness, , 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.