Meal
InterviewTime limit1sMemory limit256 MB
Pick one of two daily menu items for N days, staying within a total budget X, to maximize the sum of tastiness ratings.
- Level
Medium5 of 10
- Topics
- Greedy, Sorting, Implementation, Prefix sum
- Solved
- No attempts yet
Problem
The cafeteria in the student union building at Jeju National University has two menus. Going to corner A lets you eat a 5,000-won menu, and going to corner B lets you eat a 1,000-won menu.
Because in-person classes have started, Junwon must eat exactly one of the two cafeteria menus every day for the remaining days of the semester. The two menus for the days are already announced, and Junwon has already rated how tasty each menu is on each day.
Junwon may spend at most won in total on the cafeteria over the days.
Choose Junwon's menus over the days so that the sum of the tastiness of the chosen menus is maximized.
Input
The first line gives two integers and .
Each of the next lines gives the tastiness of the 5,000-won menu available on that day and the tastiness of the 1,000-won menu available on that day, separated by a space.
Output
Print the maximum possible sum of the tastiness of the menus Junwon chooses.
Constraints
- ,