Sangheon's Course Registration Challenge
InterviewTime limit1sMemory limit1024 MB
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 , he cannot keep his GPA up, so he wants to register for courses whose total credits are at most . There are courses available, numbered 1 through . Sangheon's preference for course is , and its credit count is . Write a program that finds a way to register so that the total credits are at most 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 () and (). Each of the next lines contains two integers () and ().
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.