CodeForces

来源:互联网 发布:明星导航语音软件 编辑:程序博客网 时间:2024/06/16 15:46

C. Servers
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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

It is known that during the day q tasks will come, the i-th of them is characterized with three integers: ti — the moment in seconds in which the task will come, ki — the number of servers needed to perform it, and di — the time needed to perform this task in seconds. All tiare distinct.

To perform the i-th task you need ki servers which are unoccupied in the second ti. After the servers begin to perform the task, each of them will be busy over the next di seconds. Thus, they will be busy in seconds ti, ti + 1, ..., ti + di - 1. For performing the task, kiservers with the smallest ids will be chosen from all the unoccupied servers. If in the second ti 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.

Input

The first line contains two positive integers n and q (1 ≤ n ≤ 1001 ≤ q ≤ 105) — the number of servers and the number of tasks.

Next q lines contains three integers each, the i-th line contains integers tiki and di (1 ≤ ti ≤ 1061 ≤ ki ≤ n1 ≤ di ≤ 1000) — the moment in seconds in which the i-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.

Output

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

Examples
input
4 31 3 22 2 13 4 3
output
6-110
input
3 23 2 35 1 2
output
33
input
8 61 3 204 2 16 5 510 1 115 3 621 8 8
output
6930-11536
Note

In the first example in the second 1 the first task will come, it will be performed on the servers with ids 12 and 3 (the sum of the ids equals 6) during two seconds. In the second 2 the second task will come, it will be ignored, because only the server 4 will be unoccupied at that second. In the second 3 the third task will come. By this time, servers with the ids 12 and 3 will be unoccupied again, so the third task will be done on all the servers with the ids 123 and 4 (the sum of the ids is 10).

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


题意:给定n个职员和q个工作 每个工作有起始时间 需要的人数和经过的时间 求干每个工作的人的编号的和 人不够输出-1


思路:开始时没有注意要优先选择编号小的职员(其实是错了在codeforce答案里看见的)用了优先队列鼓捣不出来 仔细想想没这么麻烦


#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <queue>#include <stack>#include <map>#include <cmath>#include <vector>#define max_ 100010#define inf 0x3f3f3f3f#define ll long longusing namespace std;int m,n;int num[120];vector<int>v;int main(int argc, char const *argv[]){scanf("%d%d",&n,&m);while(m--){int be,cnt,lg,i;scanf("%d%d%d",&be,&cnt,&lg);int sum=0,ct=0;;for(i=1;i<=n;i++){if(num[i]<=be){cnt--;sum+=i;v.push_back(i);}if(cnt==0)break;}if(cnt==0){printf("%d\n",sum );while(!v.empty()){num[v.back()]=be+lg;v.pop_back();}}else{printf("-1\n");v.clear();}}return 0;}


原创粉丝点击