CF747C.Servers

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

There are nn servers in a laboratory, each of them can perform tasks. Each server has a unique id — integer from 11 to nn .

It is known that during the day qq tasks will come, the ii -th of them is characterized with three integers: tit_{i} — the moment in seconds in which the task will come, kik_{i} — the number of servers needed to perform it, and did_{i} — the time needed to perform this task in seconds. All tit_{i} are distinct.

To perform the ii -th task you need kik_{i} servers which are unoccupied in the second tit_{i} . After the servers begin to perform the task, each of them will be busy over the next did_{i} seconds. Thus, they will be busy in seconds ti,ti+1,...,ti+di1t_{i},t_{i}+1,...,t_{i}+d_{i}-1 . For performing the task, kik_{i} servers with the smallest ids will be chosen from all the unoccupied servers. If in the second tit_{i} there are not enough unoccupied servers, the task is ignored.

Write the program that determines which tasks will be performed and which will be ignored.

输入格式

The first line contains two positive integers nn and qq ( 1<=n<=1001<=n<=100 , 1<=q<=1051<=q<=10^{5} ) — the number of servers and the number of tasks.

Next qq lines contains three integers each, the ii -th line contains integers tit_{i} , kik_{i} and did_{i} ( 1<=ti<=1061<=t_{i}<=10^{6} , 1<=ki<=n1<=k_{i}<=n , 1<=di<=10001<=d_{i}<=1000 ) — the moment in seconds in which the ii -th task will come, the number of servers needed to perform it, and the time needed to perform this task in seconds. The tasks are given in a chronological order and they will come in distinct seconds.

输出格式

Print qq lines. If the ii -th task will be performed by the servers, print in the ii -th line the sum of servers' ids on which this task will be performed. Otherwise, print -1.

输入输出样例

  • 输入#1

    4 3
    1 3 2
    2 2 1
    3 4 3
    

    输出#1

    6
    -1
    10
    
  • 输入#2

    3 2
    3 2 3
    5 1 2
    

    输出#2

    3
    3
    
  • 输入#3

    8 6
    1 3 20
    4 2 1
    6 5 5
    10 1 1
    15 3 6
    21 8 8
    

    输出#3

    6
    9
    30
    -1
    15
    36
    

说明/提示

In the first example in the second 11 the first task will come, it will be performed on the servers with ids 11 , 22 and 33 (the sum of the ids equals 66 ) during two seconds. In the second 22 the second task will come, it will be ignored, because only the server 44 will be unoccupied at that second. In the second 33 the third task will come. By this time, servers with the ids 11 , 22 and 33 will be unoccupied again, so the third task will be done on all the servers with the ids 11 , 22 , 33 and 44 (the sum of the ids is 1010 ).

In the second example in the second 33 the first task will come, it will be performed on the servers with ids 11 and 22 (the sum of the ids is 33 ) during three seconds. In the second 55 the second task will come, it will be performed on the server 33 , because the first two servers will be busy performing the first task.

首页