TopCoder problem "TimeToSay" used in East China Round 1 (Division I Level Two)



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)
    
{1, 21, 79}
{20, 30, 25}
Returns: 50
In this case, we cannot talk to both the 2nd and 3rd people because we would die.
1)
    
{100}
{20}
Returns: 0
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

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=8790

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=12226&pm=8790

Writer:

DStepanenko

Testers:

PabloGilberto , Olexiy , lovro , ivan_metelsky

Problem categories:

Dynamic Programming, Recursion, Search, Simulation