Problem Statement |
|
You've been patient for too long. Now it's time to tell everybody what you think about them.
You are given int[]s lostHealth and joy. After you talk to person i, you will lose lostHealth[i] units of health and gain joy[i] units of joy. You can talk to each person at most once. You do not have to talk to people in any particular order.
Your goal is to gain as much joy as possible. You initially have 100 units of health and 0 units of joy. If your health ever becomes zero or negative, you will die and end up having no joy at all. Return the maximum amount of joy you can get.
|
|
Definition |
| Class: | TimeToSay | Method: | maximumJoy | Parameters: | int[], int[] | Returns: | int | Method signature: | int maximumJoy(int[] lostHealth, int[] joy) | (be sure your method is public) |
|
|
|
|
Constraints |
- | lostHealth will contain between 1 and 20 elements, inclusive. |
- | joy will contain between 1 and 20 elements, inclusive. |
- | lostHealth and joy will contain the same number of elements. |
- | Each element of lostHealth will be between 0 and 100, inclusive. |
- | Each element of joy will be between 0 and 100, inclusive. |
|
Examples |
0) | |
| | Returns: 50 | In this case, we cannot talk to both the 2nd and 3rd people because we would die. |
|
|
1) | |
| |
2) | |
| {100, 15, 1, 2, 3, 4, 6, 5} | {49, 40, 1, 2, 3, 4, 5, 4} |
| Returns: 59 | |
|
3) | |
| {100, 50, 20, 13} | {20, 30, 40, 50} |
| Returns: 120 | |
|
4) | |
| {100, 26, 13, 17, 24, 33, 100, 99} | {34, 56, 21, 1, 24, 34, 100, 99} |
| Returns: 135 | |
|
5) | |
| {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1} | {100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100} |
| Returns: 1200 | |
|