CF1612E.Messages

普及/提高-

通过率:0%

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 tkit \le k_i , then the ii -th student will read all the pinned messages; but if t>kit > 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!

输入格式

The first line contains one integer nn ( 1n21051 \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 ( 1mi21051 \le m_i \le 2 \cdot 10^5 ; 1ki201 \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.

输出格式

In the first line, print one integer tt ( 1t21051 \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 ( 1ci21051 \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.

输入输出样例

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

首页