Weightage | codechef solution

You are in the year 2050 and many things have changed. Of course, there are flying cars and vacations on Mars are common, but it’s time to focus on the most important thing of all: IOI selections.

IOI selections now only allow each country to send one student to IOI. Now, since you’re no longer a student, you’ve decided to organise the selection rounds to choose the student who will go to IOI from Siruseri.

You organise two contests. Each contest is out of �P points, and a participant can therefore score any integer score from 11 to �P, both inclusive. There are �N participants, numbered from 11 to �N, and each participant takes part in both of these contests.

Now, you have the scores from every participant. There is just one problem though: you are not sure how you will combine the scores from the two contests, in order to select the best participants!

Therefore, you’re now required to choose any real number �r, such that 0≤�≤1000≤r≤100. Then, if some participant has a score of �A on the first contest, and a score of �B on the second contest, their composite score will become ��+�(100−�)100100Ar+B(100−r)​. Finally, you will choose the student with the largest composite score to be Siruseri’s representative at IOI. If there is more than one student with the same largest composite score, you are allowed choose any one of these students as the representative.

Now, you want to find out the answer to one simple question: which of the students can become the representatives of Siruseri, assuming that you can choose any real value of �r between 00 and 100100, both inclusive? Again, if there are ties for the maximum composite score, you are also allowed to pick which of the tied students is the representative.

Input Format

The first line of input contains two space-separated integers, �N and �P. �N is the number of students taking part, and �P is the maximum possible score on the test.

The following �N lines of input each contain two space-separated integers, representing the scores of the students. The ��ℎith line contains ��Ai​ and ��Bi​, where ��Ai​ is the score of the ��ℎith participant on the first contest, and ��Bi​ is the score of the ��ℎith participant on the second contest. It is guaranteed that 1≤��,��≤�1≤Ai​,Bi​≤P for all 1≤�≤�1≤iN.

Output Format

On the first line of output, print a single integer �K: the number of possible representatives of Siruseri.

On the second line of output, print �K space-separated integers, the list of possible representatives of Siruseri. This list should be printed in ascending order, and should have no duplicates.

Constraints

For all subtasks, 1≤�≤2000001≤N≤200000 and 1≤�≤1071≤P≤107. Additionally, 1≤��,��≤�1≤Ai​,Bi​≤P for all 1≤�≤�1≤iN.

Subtasks

  • Subtask 1 [4 points]: �=1N=1
  • Subtask 2 [5 points]: �≤2N≤2
  • Subtask 3 [8 points]: For all students, either ��=1Ai​=1 or ��=1Bi​=1 (or possibly both).
  • Subtask 4 [18 points]: It is sufficient to consider only integer values of �r. Formally, if a student can be selected as the representative using some value of �r, there exists an integer value of �r such that they can be selected as the representative.
  • Subtask 5 [10 points]: �≤80N≤80
  • Subtask 6 [6 points]: �≤400N≤400
  • Subtask 7 [18 points]: �≤2000N≤2000
  • Subtask 8 [7 points]: �≤10P≤10
  • Subtask 9 [3 points]: �≤50P≤50
  • Subtask 10 [21 points]: No additional constraints.

Sample 1:

Input

Output

6 10
1 8
5 8
2 5
5 4
2 5
5 6
4
1 2 4 6 

Explanation:

For the first sample, choosing �=0r=0 will make the cumulative scores:

  • Person 1: 8
  • Person 2: 8
  • Person 3: 5
  • Person 4: 4
  • Person 5: 5
  • Person 6: 6

Both the 1st person and the 2nd person are potential first placers, if �=0r=0 is chosen.

Meanwhile, choosing �=100r=100 will make the cumulative scores:

  • Person 1: 1
  • Person 2: 5
  • Person 3: 2
  • Person 4: 5
  • Person 5: 2
  • Person 6: 5

The 2nd person, 4th person and 6th person are potential first placers, if �=100r=100 is chosen.

It can be shown that regardless of the value of �r you choose, the 3rd and 5th people can never be first place. So there are four people who can be first, so we output 4. On the next line, we print the list of four people who can be first: 1, 2, 4 and 6.

Click on below image to get solution link:

Leave a Reply

Your email address will not be published. Required fields are marked *

मिर्जापुर 3 के बोनस एपिसोड में मुन्ना भैया की वापसी? आपकी साँसे थम जाएंगी! ये है आपके PAN CARD की एक्सपायरी डेट, कहीं छूट तो नहीं गई? यकीन नहीं मानोगे! ये 9 जगहें हैं UP में जो ताजमहल को भी फीका कर देंगी! मेरठ: इतिहास, धर्म और खूबसूरती का संगम! घूमने के लिए ये हैं बेहतरीन जगहें रोज आंवला खाने के 10 धांसू फायदे जो आपको कर देंगे हेल्दी और फिट! Anjali Arora to play Maa Sita: रामायण फिल्म में सीता का रोल निभाएंगी अंजली अरोड़ा, तैयारियों में लगी?