A10724 | Servers
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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: $t_{i}$ — the moment in seconds in which the task will come, $k_{i}$ — the number of servers needed to perform it, and $d_{i}$ — the time needed to perform this task in seconds. All $t_{i}$ are distinct.
To perform the $i$ -th task you need $k_{i}$ servers which are unoccupied in the second $t_{i}$ . After the servers begin to perform the task, each of them will be busy over the next $d_{i}$ seconds. Thus, they will be busy in seconds $t_{i},t_{i}+1,...,t_{i}+d_{i}-1$ . For performing the task, $k_{i}$ servers with the smallest ids will be chosen from all the unoccupied servers. If in the second $t_{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.
It is known that during the day $q$ tasks will come, the $i$ -th of them is characterized with three integers: $t_{i}$ — the moment in seconds in which the task will come, $k_{i}$ — the number of servers needed to perform it, and $d_{i}$ — the time needed to perform this task in seconds. All $t_{i}$ are distinct.
To perform the $i$ -th task you need $k_{i}$ servers which are unoccupied in the second $t_{i}$ . After the servers begin to perform the task, each of them will be busy over the next $d_{i}$ seconds. Thus, they will be busy in seconds $t_{i},t_{i}+1,...,t_{i}+d_{i}-1$ . For performing the task, $k_{i}$ servers with the smallest ids will be chosen from all the unoccupied servers. If in the second $t_{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 $n$ and $q$ ( $1<=n<=100$ , $1<=q<=10^{5}$ ) — the number of servers and the number of tasks.
Next $q$ lines contains three integers each, the $i$ -th line contains integers $t_{i}$ , $k_{i}$ and $d_{i}$ ( $1<=t_{i}<=10^{6}$ , $1<=k_{i}<=n$ , $1<=d_{i}<=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.
Next $q$ lines contains three integers each, the $i$ -th line contains integers $t_{i}$ , $k_{i}$ and $d_{i}$ ( $1<=t_{i}<=10^{6}$ , $1<=k_{i}<=n$ , $1<=d_{i}<=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.
输出格式
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.
输入输出样例
输入 #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 $1$ the first task will come, it will be performed on the servers with ids $1$ , $2$ 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 $1$ , $2$ and $3$ will be unoccupied again, so the third task will be done on all the servers with the ids $1$ , $2$ , $3$ 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.
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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted