CF253E.Printer

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Let's consider a network printer that functions like that. It starts working at time 0. In each second it can print one page of a text. At some moments of time the printer receives printing tasks. We know that a printer received nn tasks. Let's number the tasks by consecutive integers from 1 to nn . Then the task number ii is characterised by three integers: tit_{i} is the time when the task came, sis_{i} is the task's volume (in pages) and pip_{i} is the task's priority. The priorities of all tasks are distinct.

When the printer receives a task, the task goes to the queue and remains there until all pages from this task are printed. The printer chooses a page to print each time when it either stops printing some page or when it is free and receives a new task. Among all tasks that are in the queue at this moment, the printer chooses the task with the highest priority and next second prints an unprinted page from this task. You can assume that a task goes to the queue immediately, that's why if a task has just arrived by time tt , the printer can already choose it for printing.

You are given full information about all tasks except for one: you don't know this task's priority. However, we know the time when the last page from this task was finished printing. Given this information, find the unknown priority value and determine the moments of time when the printer finished printing each task.

输入格式

The first line contains integer nn ( 1<=n<=500001<=n<=50000 ). Next nn lines describe the tasks. The ii -th of these lines contains three integers tit_{i} , sis_{i} and pip_{i} , separated by single spaces ( 0<=ti<=109,1<=si,pi<=1090<=t_{i}<=10^{9},1<=s_{i},p_{i}<=10^{9} ). Exactly one task (let's assume that his number is xx ) has number -1 written instead of the priority. All priorities are different. The last line contains integer TT — the time when the printer finished printing the last page of task xx ( 1<=T<=10151<=T<=10^{15} ). Numbers tit_{i} are not necessarily distinct. The tasks in the input are written in the arbitrary order.

输出格式

In the first line print integer pxp_{x} — the priority of the task number xx ( 1<=px<=1091<=p_{x}<=10^{9} , remember that all priorities should be distinct). Then print nn integers, the ii -th of them represents the moment of time when the last page of the task number ii finished printing.

It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.

输入输出样例

  • 输入#1

    3
    4 3 -1
    0 2 2
    1 3 3
    7
    

    输出#1

    4
    7 8 4
    
  • 输入#2

    3
    3 1 2
    2 3 3
    3 1 -1
    4
    

    输出#2

    4
    7 6 4
    

说明/提示

Let's consider the first test case. Let's assume that the unknown priority equals 4, then the printer's actions for each second are as follows:

  • the beginning of the 1-st second (time 0). The queue has task 2. The printer prints the first page of this task;
  • the beginning of the 2-nd second (time 1). The queue has tasks 2 and 3. The printer prints the first page of task 3;
  • the beginning of the 3-rd second (time 2). The queue has tasks 2 and 3. The printer prints the second page of task 3;
  • the beginning of the 4-th second (time 3). The queue has tasks 2 and 3. The printer prints the third (last) page of task 3. Thus, by the end of the 4-th second this task will have been printed;
  • the beginning of the 5-th second (time 4). The queue has tasks 2 and 1. The printer prints the first page of task 1;
  • the beginning of the 6-th second (time 5). The queue has tasks 2 and 1. The printer prints the second page of task 1;
  • the beginning of the 7-th second (time 6). The queue has tasks 2 and 1. The printer prints the third (last) page of task 1. Thus, by the end of the 7-th second this task will have been printed;
  • the beginning of the 8-th second (time 7). The queue has task 2. The printer prints the second (last) page of task 2. Thus, by the end of the 8-th second this task will have been printed.

In the end, task number 1 will have been printed by the end of the 7-th second, as was required. And tasks 2 and 3 are printed by the end of the of the 8-th and the 4-th second correspondingly.

首页