编程介的小学生 2017-08-25 03:27 采纳率: 20.5%
浏览 672
已采纳

Getting Meal

Life in university passes very fast. However, the memory about the dining hall always lasts long.

Regard the dining hall as a 2D plane. Assume that in the dining hall, there is a window at every point (x, 0) for all integer x where students can get meals. In front of every window, there is a queue waiting for getting meals. The i-th person in the queue in front of window (x, 0) is at point (x, i). Every time, the student in (x, 1) gets the meal and leave the queue, then all the students in the queue go one unit toward the window.

Also, sometimes, a new window may be opened, and some student would go to the new window in order to get the meal earlier. Assume the new window opened is in (x, 0), and the following conditions hold.

A new window is only opened at the beginning of a second and no two windows will be opened at the same time.
Students will go to another queue only at the second the corresponding window is opened.
Students who go to the new queue will be lined up in the order of the distance between his/her original position and the new window. The nearer one goes ahead. But if some students have the same distance, one of them will help others get meals so that they can be considered as one student in the queue.
It takes one second for a student to get meal even if he/she should get for others.
It takes one second for a student to go to the queue of the new window, despite how far he/she is from the window.
The strategy students choose whether to go to the new queue is that if going to the new queue will not make him/her get meal later, he/she will choose to go, otherwise he/she will stay in the original queue. Also, every student knows that other students take the same strategy so that they can figure out whether to go.
With the status at the beginning of the 0th second given, you should tell me at which window does every student get meals.

Input

The input contains multiple test cases. For each case, the first line contains two integers n, m (0 ≤ n ≤ 100, 0 ≤ m ≤ 100) indicating the number of windows opened at the beginning of the 0th second and the number of windows to be opened. The next n lines each contains two integers xi, qi (0 ≤ qi ≤ 100, xi is a non-negtive signed 32-bit integer), which mean the window is at (xi, 0) and the number of students waiting in front of the window is qi. The next m lines each contains two integers xi, ti (both within 32-bit signed integers, and are non-negative), which mean the window at (xi, 0) is opened at the beginning of tith second. All xi in a case will be different.

Output

For each case, print one line containing the x coordinates where each student gets meal. The student with smaller x coordinate at 0th second should be printed first. If the x coordinates are the same, the one being closer to the window should be printed first.

Sample Input

3 1
4 5
6 5
7 0
5 1
Sample Output

4 4 5 4 5 6 6 5 6 5

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-08-27 15:35
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。