编程介的小学生 2017-11-24 09:47 采纳率: 20.5%
浏览 611
已采纳

Parking Log

Problem Description
The parking lot in the center of the capital has N parking spaces. You are asked to develop a program to write the parking log of the lot. The program is required to record such two operations which may happen in the lot:

A: A motorcade with Mi cars applies for Mi parking spaces in a row, namely, continuous spaces [Si,Si+Mi-1]. A special constraint is that the number of free spaces between the coming motorcade and the last car parking before Si, should not be larger than Li. Note that, this constraint has no effect if there is no car before Si. What's more, the number of free spaces between the coming motorcade and the first car parking after Si+Mi-1 should not be larger than Ri. Also, you should ignore this constraint when Si+Mi-1 is last occupied space. The space with the smallest Si is selected when there are several candidate start places. The motorcade will leave if there are no spaces satisfying the conditions. After one motorcade is parked, its parking limits Li and Ri can be ignored when finding parking places for later coming motorcades. Your task is to find the Si, and return it as result.

B. The k-th motorcade counted from left to right leaves the lot. Ignore this operation if there are no more than k motorcades in the parking lot.

In the very beginning, the spaces in the lot are all free.

Input
First line of the input is a single integer T(T <= 10), indicates there are T test cases.
For each test case, the first line is two integers N(1 <= N <= 50000) Q(1 <= Q <= 100000), representing the size of the lot and the number of operations.
The following Q lines give the operations, in which lines with one char and three integers as "A M L R" (0 < M,L,R <= 50000) representing operations of type A, and lines with one char and a single number are of type B.

Output
For each test case, you should output "Case #k:" first. After that, your program should output the result place for each operation A, -1 if no place available.

Sample Input
2
90 5
A 77 2 2
B 3
B 1
A 53 2 3
A 7 3 3
7 15
A 3 1 1
A 1 1 1
B 1
A 1 1 1
A 1 1 1
B 2
A 2 1 1
A 1 1 1
A 2 1 1
A 1 1 1
B 4
B 3
B 2
A 1 1 1
A 2 1 1

Sample Output
Case #1:
1
1
54
Case #2:
1
4
2
1
2
5
6
-1
-1
3

  • 写回答

1条回答 默认 最新

  • threenewbee 2018-05-06 13:48
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了