CF1612E.Messages

普及+/提高

通过率:0%

时间限制:3.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

Monocarp is a tutor of a group of nn students. He communicates with them using a conference in a popular messenger.

Today was a busy day for Monocarp — he was asked to forward a lot of posts and announcements to his group, that's why he had to write a very large number of messages in the conference. Monocarp knows the students in the group he is tutoring quite well, so he understands which message should each student read: Monocarp wants the student ii to read the message mim_i.

Of course, no one's going to read all the messages in the conference. That's why Monocarp decided to pin some of them. Monocarp can pin any number of messages, and if he wants anyone to read some message, he should pin it — otherwise it will definitely be skipped by everyone.

Unfortunately, even if a message is pinned, some students may skip it anyway. For each student ii, Monocarp knows that they will read at most kik_i messages. Suppose Monocarp pins tt messages; if t≤kit \le k_i, then the ii-th student will read all the pinned messages; but if t>kit \gt k_i, the ii-th student will choose exactly kik_i random pinned messages (all possible subsets of pinned messages of size kik_i are equiprobable) and read only the chosen messages.

Monocarp wants to maximize the expected number of students that read their respective messages (i.e. the number of such indices ii that student ii reads the message mim_i). Help him to choose how many (and which) messages should he pin!

Monocarp 是一个由 nn 名学生组成的小组的导师。他通过一款流行即时通讯软件中的群聊与学生们交流。

今天对 Monocarp 来说十分忙碌——他被要求向该群转发大量帖子和通知,因此他在群聊中发送了数量庞大的消息。Monocarp 对自己所指导的学生非常了解,因此他清楚每条消息应由哪位学生阅读:Monocarp 希望第 ii 位学生阅读第 mim_i 条消息。

当然,没有人会阅读群聊中的所有消息。因此,Monocarp 决定将其中一部分消息置顶(即“pin”)。Monocarp 可以置顶任意数量的消息;若希望某位学生阅读某条消息,则他必须将该消息置顶——否则该消息必然被所有人忽略。

不幸的是,即使一条消息被置顶,某些学生仍可能跳过它。对于每位学生 ii,Monocarp 知道他们最多只会阅读 kik_i 条消息。假设 Monocarp 共置顶了 tt 条消息:若 t≤kit \le k_i,则第 ii 位学生将阅读全部 tt 条置顶消息;但若 t>kit > k_i,则第 ii 位学生将从所有置顶消息中随机选择恰好 kik_i 条(所有大小为 kik_i 的置顶消息子集等概率被选中),并仅阅读所选中的消息。

Monocarp 希望最大化期望意义上阅读到各自指定消息的学生人数(即满足“第 ii 位学生阅读了消息 mim_i”这一条件的下标 ii 的个数的期望值)。请帮助他确定:应置顶多少条消息?具体是哪几条?

输入格式

The first line contains one integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) — the number of students in the conference.

Then nn lines follow. The ii-th line contains two integers mim_i and kik_i (1≤mi≤2⋅1051 \le m_i \le 2 \cdot 10^5; 1≤ki≤201 \le k_i \le 20) — the index of the message which Monocarp wants the ii-th student to read and the maximum number of messages the ii-th student will read, respectively.

第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)—— 表示会议中学生的数量。

接下来是 nn 行。第 ii 行包含两个整数 mim_i 和 kik_i(1≤mi≤2⋅1051 \le m_i \le 2 \cdot 10^5;1≤ki≤201 \le k_i \le 20)—— 分别表示 Monocarp 希望第 ii 个学生阅读的消息编号,以及第 ii 个学生最多会阅读的消息数量。

输出格式

In the first line, print one integer tt (1≤t≤2⋅1051 \le t \le 2 \cdot 10^5) — the number of messages Monocarp should pin. In the second line, print tt distinct integers c1c_1, c2c_2, ..., ctc_t (1≤ci≤2⋅1051 \le c_i \le 2 \cdot 10^5) — the indices of the messages Monocarp should pin. The messages can be listed in any order.

If there are multiple answers, print any of them.

第一行输出一个整数 tt(1≤t≤2⋅1051 \le t \le 2 \cdot 10^5)—— Monocarp 应当置顶的消息数量。
第二行输出 tt 个互不相同的整数 c1c_1, c2c_2, ..., ctc_t(1≤ci≤2⋅1051 \le c_i \le 2 \cdot 10^5)—— Monocarp 应当置顶的消息的索引。这些消息可以以任意顺序列出。

若存在多个合法答案,输出其中任意一个即可。

输入输出样例

  • 输入#1

    3
    10 1
    10 2
    5 2

    输出#1

    2
    5 10
  • 输入#2

    3
    10 1
    5 2
    10 1

    输出#2

    1
    10
  • 输入#3

    4
    1 1
    2 2
    3 3
    4 4

    输出#3

    3
    2 3 4
  • 输入#4

    3
    13 2
    42 2
    37 2

    输出#4

    3
    42 13 37

说明/提示

Let's consider the examples from the statement.

  1. In the first example, Monocarp pins the messages 55 and 1010.

    • if the first student reads the message 55, the second student reads the messages 55 and 1010, and the third student reads the messages 55 and 1010, the number of students which have read their respective messages will be 22;
    • if the first student reads the message 1010, the second student reads the messages 55 and 1010, and the third student reads the messages 55 and 1010, the number of students which have read their respective messages will be 33.

    So, the expected number of students which will read their respective messages is 52\frac{5}{2}.

  2. In the second example, Monocarp pins the message 1010.

    • if the first student reads the message 1010, the second student reads the message 1010, and the third student reads the message 1010, the number of students which have read their respective messages will be 22.

    So, the expected number of students which will read their respective messages is 22. If Monocarp had pinned both messages 55 and 1010, the expected number of students which read their respective messages would have been 22 as well.

  3. In the third example, the expected number of students which will read their respective messages is 83\frac{8}{3}.

  4. In the fourth example, the expected number of students which will read their respective messages is 22.

我们来考虑题目陈述中的例子。

  1. 在第一个例子中,Monocarp 将消息 55 和 1010 固定(置顶)。

    • 若第一位学生阅读了消息 55,第二位学生阅读了消息 55 和 1010,第三位学生也阅读了消息 55 和 1010,则已阅读各自对应消息的学生人数为 22;
    • 若第一位学生阅读了消息 1010,第二位学生阅读了消息 55 和 1010,第三位学生也阅读了消息 55 和 1010,则已阅读各自对应消息的学生人数为 33。

    因此,阅读了各自对应消息的学生人数的期望值为 52\frac{5}{2}。

  2. 在第二个例子中,Monocarp 将消息 1010 固定(置顶)。

    • 若第一位学生阅读了消息 1010,第二位学生阅读了消息 1010,第三位学生也阅读了消息 1010,则已阅读各自对应消息的学生人数为 22。

    因此,阅读了各自对应消息的学生人数的期望值为 22。若 Monocarp 同时固定(置顶)了消息 55 和 1010,则阅读了各自对应消息的学生人数的期望值同样为 22。

  3. 在第三个例子中,阅读了各自对应消息的学生人数的期望值为 83\frac{8}{3}。

  4. 在第四个例子中,阅读了各自对应消息的学生人数的期望值为 22。

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

首页