Greeting
InterviewTime limit2sMemory limit128 MB
Given health costs and joy values for up to 20 people, pick a subset maximizing total joy while keeping total health loss below 100.
- Level
Easy3 of 10
- Topics
- Dynamic programming
- Solved
- No attempts yet
Problem
Sejun has spent a long time in the hospital after surgery. Now he wants to thank the people who cared about him while he was hospitalized.
There are N people, numbered from 1 to N. If Sejun greets person i, he loses L[i] health and gains J[i] joy. He can greet each person at most once.
Sejun starts with 100 health and 0 joy. If his health becomes 0 or negative, he cannot feel any joy. Choose whom he greets so that his health remains positive, and find the maximum joy he can gain.
Input
The first line contains the number of people, N. (N <= 20)
The second line contains the health losses L[i] for people 1 through N, in order.
The third line contains the joy values J[i] for people 1 through N, in order.
Every health loss and joy value is an integer between 0 and 100, inclusive.
Output
Print the maximum joy Sejun can gain.