A11519 | Too Easy Problems
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are preparing for an exam on scheduling theory. The exam will last for exactly $T$ milliseconds and will consist of $n$ problems. You can either solve problem $i$ in exactly $t_{i}$ milliseconds or ignore it and spend no time. You don't need time to rest after solving a problem, either.
Unfortunately, your teacher considers some of the problems too easy for you. Thus, he assigned an integer $a_{i}$ to every problem $i$ meaning that the problem $i$ can bring you a point to the final score only in case you have solved no more than $a_{i}$ problems overall (including problem $i$ ).
Formally, suppose you solve problems $p_{1},p_{2},...,p_{k}$ during the exam. Then, your final score $s$ will be equal to the number of values of $j$ between 1 and $k$ such that $k<=a_{pj}$ .
You have guessed that the real first problem of the exam is already in front of you. Therefore, you want to choose a set of problems to solve during the exam maximizing your final score in advance. Don't forget that the exam is limited in time, and you must have enough time to solve all chosen problems. If there exist different sets of problems leading to the maximum final score, any of them will do.
Unfortunately, your teacher considers some of the problems too easy for you. Thus, he assigned an integer $a_{i}$ to every problem $i$ meaning that the problem $i$ can bring you a point to the final score only in case you have solved no more than $a_{i}$ problems overall (including problem $i$ ).
Formally, suppose you solve problems $p_{1},p_{2},...,p_{k}$ during the exam. Then, your final score $s$ will be equal to the number of values of $j$ between 1 and $k$ such that $k<=a_{pj}$ .
You have guessed that the real first problem of the exam is already in front of you. Therefore, you want to choose a set of problems to solve during the exam maximizing your final score in advance. Don't forget that the exam is limited in time, and you must have enough time to solve all chosen problems. If there exist different sets of problems leading to the maximum final score, any of them will do.
输入格式
The first line contains two integers $n$ and $T$ ( $1<=n<=2·10^{5}$ ; $1<=T<=10^{9}$ ) — the number of problems in the exam and the length of the exam in milliseconds, respectively.
Each of the next $n$ lines contains two integers $a_{i}$ and $t_{i}$ ( $1<=a_{i}<=n$ ; $1<=t_{i}<=10^{4}$ ). The problems are numbered from 1 to $n$ .
Each of the next $n$ lines contains two integers $a_{i}$ and $t_{i}$ ( $1<=a_{i}<=n$ ; $1<=t_{i}<=10^{4}$ ). The problems are numbered from 1 to $n$ .
输出格式
In the first line, output a single integer $s$ — your maximum possible final score.
In the second line, output a single integer $k$ ( $0<=k<=n$ ) — the number of problems you should solve.
In the third line, output $k$ distinct integers $p_{1},p_{2},...,p_{k}$ ( $1<=p_{i}<=n$ ) — the indexes of problems you should solve, in any order.
If there are several optimal sets of problems, you may output any of them.
In the second line, output a single integer $k$ ( $0<=k<=n$ ) — the number of problems you should solve.
In the third line, output $k$ distinct integers $p_{1},p_{2},...,p_{k}$ ( $1<=p_{i}<=n$ ) — the indexes of problems you should solve, in any order.
If there are several optimal sets of problems, you may output any of them.
输入输出样例
输入 #1
5 300 3 100 4 150 4 80 2 90 2 300
输出 #1
2 3 3 1 4
输入 #2
2 100 1 787 2 788
输出 #2
0 0
输入 #3
2 100 2 42 2 58
输出 #3
2 2 1 2
In the first example, you should solve problems 3, 1, and 4. In this case you'll spend $80+100+90=270$ milliseconds, falling within the length of the exam, 300 milliseconds (and even leaving yourself 30 milliseconds to have a rest). Problems 3 and 1 will bring you a point each, while problem 4 won't. You'll score two points.
In the second example, the length of the exam is catastrophically not enough to solve even a single problem.
In the third example, you have just enough time to solve both problems in $42+58=100$ milliseconds and hand your solutions to the teacher with a smile.
In the second example, the length of the exam is catastrophically not enough to solve even a single problem.
In the third example, you have just enough time to solve both problems in $42+58=100$ milliseconds and hand your solutions to the teacher with a smile.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted