TopCoder problem "RegimentArming" used in SRM 269 (Division II Level Three)



Problem Statement

    

Some guns are placed in a line. The guns are sorted by their type. You will get N consecutive guns for your regiment and, of course, you want to maximize the sum of your guns' powers.

You will be given int[]s counts and powers. counts[i] is the number of guns of type i, and powers[i] is the power of each gun of type i. Guns are given in the same order that they are in the line. Return the maximal sum of gun power that you can get.

 

Definition

    
Class:RegimentArming
Method:chooseGuns
Parameters:int[], int[], int
Returns:int
Method signature:int chooseGuns(int[] counts, int[] powers, int N)
(be sure your method is public)
    
 

Constraints

-counts will have between 1 and 50 elements, inclusive.
-powers will have between 1 and 50 elements, inclusive.
-counts and powers will have the same number of elements.
-Each element of counts will be between 1 and 1000000, inclusive.
-Each element of powers will be between 1 and 1000, inclusive.
-N will be between 1 and 1000000, inclusive.
-N will be between 1 and the sum of elements in counts, inclusive.
 

Examples

0)
    
{5, 37, 4}
{7, 2, 8}
20
Returns: 65
We can take 5 guns with power 7 and 15 guns with power 2.
1)
    
{5, 37, 4}
{7, 4, 8}
20
Returns: 96
We can take 4 guns with power 8 and 16 guns with power 4.
2)
    
{5, 37, 4}
{7, 4, 8}
46
Returns: 215
We can take all the guns.
3)
    
{761,263,698,811,201,493,385,621,626,171}
{204,464,251,438,241,351,181,915,473,589}
2515
Returns: 1264085

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=8002&pm=4831

Writer:

Andrew_Lazarev

Testers:

PabloGilberto , brett1479 , Olexiy

Problem categories:

Brute Force