CF913D.Too Easy Problems

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

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__p__j.

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.

你正在为一场关于调度理论的考试做准备。考试时长恰好为 TT 毫秒,共包含 nn 道题目。对于第 ii 道题,你可以选择花费恰好 tit_i 毫秒将其解出,也可以选择忽略它,从而不花费任何时间。解完一道题后,你无需额外休息时间。

遗憾的是,老师认为其中一些题目对你而言过于简单。因此,他为每道题 ii 分配了一个整数 aia_i,其含义是:仅当你在整场考试中解出的题目总数(含本题)不超过 aia_i 时,该题才能为你最终得分贡献 1 分。

形式化地,假设你在考试中解出了题目 p1, p2, …, pkp_1,\,p_2,\,\dots,\,p_k(共 kk 道)。那么你的最终得分 ss 等于满足 k≤apjk \le a_{p_j} 的下标 jj(其中 1≤j≤k1 \le j \le k)的个数。

你已猜到考试的第一道真实题目就摆在眼前。因此,你希望预先选定一组题目来求解,使得最终得分最大化。请注意:考试有严格的时间限制,你必须确保所选题目的总耗时不超过 TT。若存在多个不同题目集合均可达到最大最终得分,输出任意一个即可。

输入格式

The first line contains two integers n and T (1 ≤ n ≤ 2·105; 1 ≤ T ≤ 109) — 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 ≤ 104). The problems are numbered from 1 to n.

第一行包含两个整数 nn 和 TT(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5;1≤T≤1091 \leq T \leq 10^9),分别表示考试中的题目数量和考试时长(单位:毫秒)。

接下来的 nn 行,每行包含两个整数 aia_i 和 tit_i(1≤ai≤n1 \leq a_i \leq n;1≤ti≤1041 \leq t_i \leq 10^4)。题目编号从 11 到 nn。

输出格式

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.

第一行输出一个整数 ss —— 你可能获得的最高最终得分。

第二行输出一个整数 kk(0≤k≤n0 \leq k \leq n)—— 你需要解决的问题个数。

第三行输出 kk 个互不相同的整数 p1, p2, …, pkp_1,\ p_2,\ \dots,\ p_k(1≤pi≤n1 \leq p_i \leq n)—— 你需要解决的问题的编号,顺序任意。

若存在多个最优的问题集合,输出其中任意一个即可。

输入输出样例

  • 输入#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.

在第一个例子中,你应该解决第 3、第 1 和第 4 题。此时你将花费 80+100+90=27080 + 100 + 90 = 270 毫秒,这在考试时长(300 毫秒)范围内(甚至还能剩下 30 毫秒休息)。第 3 题和第 1 题各为你带来 1 分,而第 4 题则不能得分。你的总得分为 2 分。

在第二个例子中,考试时长严重不足,甚至连一道题都无法完成。

在第三个例子中,你恰好有足够的时间在 42+58=10042 + 58 = 100 毫秒内解决两道题,并微笑着将解答交给老师。

输入解题思路,AI测评打分。不知道怎么写?

首页