Under construction

Still being built. Things may change

Sangheon's Course Registration Challenge

Interview

Time limit1sMemory limit1024 MB

Summary
Given N courses with preference and credits, choose a subset of at least one course with total credits at most M that maximizes total preference, and print the chosen indices.
Level

Medium5 of 10

Topics
Dynamic programming, Array
Solved
No attempts yet

Problem

At KSA, students must pick the courses they want and register for them. Sangheon worries that if his total credits go over MM, he cannot keep his GPA up, so he wants to register for courses whose total credits are at most MM. There are NN courses available, numbered 1 through NN. Sangheon's preference for course ii is PiP_i, and its credit count is CiC_i. Write a program that finds a way to register so that the total credits are at most MM and the total preference is maximized. Each course can be chosen at most once, and he must register for at least one course.

Input

The first line contains two integers NN (1≤N≤50001 \le N \le 5000) and MM (1≤M≤50001 \le M \le 5000). Each of the next NN lines contains two integers PiP_i (1≤Pi≤1051 \le P_i \le 10^5) and CiC_i (1≤Ci≤50001 \le C_i \le 5000).

Output

On the first line, print the number of courses to register for if a valid way exists, or -1 otherwise. If a way exists, print the course numbers in ascending order on the second line. If several answers exist, any of them is accepted.

Examples2

  1. Example 1

    Input
    8 13
    1 1
    9 3
    18 2
    1 2
    13 3
    7 3
    19 4
    15 4
    
    Expected output
    4
    3 5 7 8
    
  2. Example 2

    Input
    3 2
    3 4
    7 3
    4 3
    
    Expected output
    -1