Billboard
Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 20022 Accepted Submission(s): 8362
Problem Description
At the entrance tothe university, there is a huge rectangular billboard of size h*w (h isits height and w isits width). The board isthe place where all possible announcements are posted: nearest programming competitions, changes inthe dining room menu, and other important information.
On September 1, the billboard was empty. One by one, the announcements started being putonthe billboard.
Each announcement is a stripe of paper of unit height. More specifically, the i-th announcement is a rectangle of size 1 * wi.
When someone puts a new announcement onthe billboard, she would always choose the topmost possible position forthe announcement. Among all possible topmost positions she would always choose the leftmost one.
If there is no valid location for a new announcement, itisnotputonthe billboard (that's why some programming contests have no participants from this university).
Given the sizes ofthe billboard andthe announcements, your task isto find the numbers of rows in which the announcements are placed.
Input
There are multiple cases (no more than 40 cases).
The first line ofthe input filecontains three integer numbers, h, w, and n (1 <= h,w <= 10^9; 1 <= n <= 200,000) - the dimensions ofthe billboard andthenumberof announcements.
Each ofthe next n lines contains an integernumber wi (1 <= wi <= 10^9) - the width of i-th announcement.
Output
For each announcement (inthe order they are giveninthe input file) output one number - thenumberofthe row in which this announcement is placed. Rows are numbered from1to h, starting withthe top row. If an announcement can't be putonthe billboard, output "-1"for this announcement.
Sample Input
35524333
Sample Output
1213
-1
Author
hhanger@zju
Source
HDOJ 2009 Summer Exercise(5)