Sloppy Acorn Classifier
InterviewTime limit1sMemory limit1024 MB
For each acorn, find the first hole it falls out of, given that the acorn shrinks by 1 after each hole it passes.
- Level
Medium4 of 10
- Topics
- Array, Binary search
- Solved
- No attempts yet
Problem
A sloppy classifier is used to sort acorns by size.
The classifier is a tilted board with holes. The holes are numbered from 1 to , starting from the highest one. The size of hole is .

When an acorn is dropped into the classifier, it rolls past hole 1, then hole 2, and so on up to hole . The surface is rough, so the acorn shrinks by 1 after it passes each hole. For example, if an acorn has size 10 when it passes hole 1, its size is 9 when it passes hole 2. Likewise, an acorn that has passed hole 2 has size 8 when it passes hole 3.
An acorn falls into a hole when that hole's size is greater than or equal to the acorn's current size.
For each of the acorns, write a program that finds the number of the hole it falls out of. Under the given constraints, every acorn can fall out of some hole, whatever its size.
Input
The first line contains the number of holes . The second line contains the sizes of the holes , separated by spaces. The third line contains the number of acorns . The fourth line contains the sizes of the acorns , separated by spaces.
Output
For each acorn, print the number of the hole it falls out of, in the order the acorns are given. Separate the numbers with spaces.