A8385 | Machine Programming
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
One remarkable day company "X" received $k$ machines. And they were not simple machines, they were mechanical programmers! This was the last unsuccessful step before switching to android programmers, but that's another story.
The company has now $n$ tasks, for each of them we know the start time of its execution $s_{i}$ , the duration of its execution $t_{i}$ , and the company profit from its completion $c_{i}$ . Any machine can perform any task, exactly one at a time. If a machine has started to perform the task, it is busy at all moments of time from $s_{i}$ to $s_{i}+t_{i}-1$ , inclusive, and it cannot switch to another task.
You are required to select a set of tasks which can be done with these $k$ machines, and which will bring the maximum total profit.
The company has now $n$ tasks, for each of them we know the start time of its execution $s_{i}$ , the duration of its execution $t_{i}$ , and the company profit from its completion $c_{i}$ . Any machine can perform any task, exactly one at a time. If a machine has started to perform the task, it is busy at all moments of time from $s_{i}$ to $s_{i}+t_{i}-1$ , inclusive, and it cannot switch to another task.
You are required to select a set of tasks which can be done with these $k$ machines, and which will bring the maximum total profit.
输入格式
The first line contains two integer numbers $n$ and $k$ ( $1<=n<=1000$ , $1<=k<=50$ ) — the numbers of tasks and machines, correspondingly.
The next $n$ lines contain space-separated groups of three integers $s_{i},t_{i},c_{i}$ ( $1<=s_{i},t_{i}<=10^{9}$ , $1<=c_{i}<=10^{6}$ ), $s_{i}$ is the time where they start executing the $i$ -th task, $t_{i}$ is the duration of the $i$ -th task and $c_{i}$ is the profit of its execution.
The next $n$ lines contain space-separated groups of three integers $s_{i},t_{i},c_{i}$ ( $1<=s_{i},t_{i}<=10^{9}$ , $1<=c_{i}<=10^{6}$ ), $s_{i}$ is the time where they start executing the $i$ -th task, $t_{i}$ is the duration of the $i$ -th task and $c_{i}$ is the profit of its execution.
输出格式
Print $n$ integers $x_{1},x_{2},...,x_{n}$ . Number $x_{i}$ should equal $1$ , if task $i$ should be completed and otherwise it should equal $0$ .
If there are several optimal solutions, print any of them.
If there are several optimal solutions, print any of them.
输入输出样例
输入 #1
3 1 2 7 5 1 3 3 4 1 3
输出 #1
0 1 1
输入 #2
5 2 1 5 4 1 4 5 1 3 2 4 1 2 5 6 1
输出 #2
1 1 0 0 1
In the first sample the tasks need to be executed at moments of time 2 ... 8, 1 ... 3 and 4 ... 4, correspondingly. The first task overlaps with the second and the third ones, so we can execute either task one (profit 5) or tasks two and three (profit 6).
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted