Cramming
InterviewTime limit2sMemory limit256 MB
Given N chapters, each with a study time and a score, choose a subset whose total study time fits in T to maximize the total score.
- Level
Easy3 of 10
- Topics
- Dynamic programming, Array, Greedy, Brute force
- Solved
- No attempts yet
Problem
Junseok became the president of ChAOS (Chung-ang Algorithm Organization and Study), the work piled up, and he never got around to studying during the exam period. Now it is the night before the exam. The professor did post two hints beforehand.
- No question mixes several chapters.
- Each chapter gets exactly one question. That question can only be solved by someone who knows everything in the chapter.
The professor also wrote down the score of each chapter next to the hints. Assume Junseok gets a chapter's question right if he studies that chapter for its estimated study time or longer. A chapter is either studied or not studied, and there is no partial credit.
Find the highest total score Junseok can reach with the time he has left.
Input
The first line contains the number of chapters on the exam () and the total time available before the exam (), separated by a space.
Each of the next lines contains the estimated study time () of one chapter and the score () of that chapter's question, separated by a space.
Output
Print the highest score Junseok can get on the first line.