Campus
Time limit1sMemory limit512 MB
For each room number, find its floor given that each entrance has x rooms on floors divisible by k and y rooms otherwise, with room numbering continuing across entrances.
- Level
Medium5 of 10
- Topics
- Math, Binary search, Implementation, Prefix sum
- Solved
- No attempts yet
Problem
The new campus building of Byteburg University has floors, numbered from 1 to going up. Student rooms are located in several entrances.
In each entrance, floors whose number is a multiple of have rooms, and the remaining floors have rooms.
Rooms within an entrance are numbered with consecutive positive integers. The rooms on the first floor have the smallest numbers in that entrance, then come the rooms on the second floor, and so on. The rooms in the first entrance are numbered starting from 1, and in each following entrance room numbering starts with the number right after the largest room number in the previous entrance.
Figure 1 shows the room numbers in a building with floors, 3 entrances, and parameters , , .
Figure 1. An example of room numbering in a building
To assign students to rooms, the campus administration must quickly determine the floor of a room from its number.
Given the numbers , , , and a list of room numbers, write a program that determines the floor of each room.
Input
The first line of the input file contains the positive integers , , , (, , ). Adjacent numbers are separated by exactly one space.
The second line of the input file contains the positive integer , the number of room numbers whose floors must be determined ().
The third line contains integers , the room numbers (). You may assume that the building has enough entrances that all rooms with the given numbers exist.
Output
Print numbers, one per line. For each room number in the input file, print the number of the floor on which it is located.