Bucketing Continuous Values
Quillon Energy wants a measured column turned into bands, because its effect on consumption is not smooth -- the step from the first band to the second matters far more than the step from the fourth to the fifth, and a model fed the raw number cannot express that. The band edges are handed over as a sorted list, and m edges make m - 1 bands. A reading sitting exactly on an edge belongs to the band that starts there, not to the one that ends there. The topmost band is the exception: it takes its own upper edge too. Readings outside the edges are not errors -- anything under the first edge joins the bottom band, anything over the last joins the top one. The bands are not all the same width.
Task: Print the band each reading falls into.
Input
The first line holds one integer n, the number of readings. The second line holds the n readings separated by single spaces. The third line holds one integer m, the number of edges. The fourth line holds the m edges in increasing order.
Output
n lines, one per reading, in the order the readings arrived. Each holds the band's position, counting the bottom band as 0.
Example:
Input:
5
5 15 25 10 30
4
0 10 20 30
Output:
0
1
2
1
2
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in