Computer Lab
Time limit4sMemory limit512 MB
New students each take the middle seat of the longest empty stretch, and each query asks where a given arrival sits.
- Level
Medium7 of 10
- Topics
- Heap, Divide and conquer, Simulation
- Solved
- No attempts yet
Problem
The lab at CSHS (Computer Science High School) has computers in a row. The computers are numbered to from left to right.
students are already sitting in the lab, at computers , , ..., . Self study starts soon, so more students come in and use one free computer each.
A student dislikes having another student look at their monitor, so each student who comes in takes a seat this way.
- Choose the run of consecutive computers with no student that holds the most computers. If there are several such runs, choose the leftmost one.
- Sit at the computer in the exact middle of the chosen run. If the run holds an even number of computers, sit at the left one of the two middle computers.
The students who are already seated entered first. So for , the -th student to enter sits at computer , and for , the -th student to enter is the -th student who takes a seat by the rule above.
Jinhwan has a team project with friends, so he needs to know where they sit. He knows the position of each friend in the entering order. Help Jinhwan and find the seat of each friend.
Input
The first line contains the number of computers , the number of students already seated , and the number of friends .
The second line contains integers. The -th value is the position of a seated student. Note that the students already seated may not have taken their seats by the rule above.
The third line contains integers. The -th value is , the position of the -th friend in the order of entering the lab.
and are ascending. That is, and always hold.
Output
Print lines. Line holds the number of the computer where the -th friend sits. The integers involved go past the range of a 32-bit integer, so use a 64-bit integer type.