Statistics

Problem Statement for "Diet"

Problem Statement

PROBLEM STATEMENT
Stan Ford is on a diet.  His friends have been telling him that he's gained
about 15 pounds since he started college at UC Berkeley (yes, an unfortunate
name for a Cal student).  Therefore he decided he's going to keep himself under
a certain number of Calories (also known as kilocalories).  He will select
foods such that he gets as close to his target as possible without exceeding it.

You will be given an int[] of Calorie content for food, and an int representing
his target goal.  Return the closest he can get to this target (including the
target itself) without exceeding it.

Each food item may only be used once.

DEFINITION
Class name: Diet
Method name: maxCal
Parameters: int[], int
Returns: int
The method signature is:
int maxCal(int[] Calories, int maxCal)
Be sure your method is public.

TopCoder will ensure the following:
*Calories will contain between 1 and 15 elements, inclusive.
*each element of Calories will be an int between 100 and 1000, inclusive.
*maxCal will be an int between 1500 and 2500, inclusive.

EXAMPLES
Cals={200,300,200,100,850,650}
maxCal=1550
Eating items 0, 1, 2, and 4, Stan gets his full 1550 Calories.

Cals={200,300,100,850,650}
maxCal=1550
Eating items 3 and 4, Stan gets 1500 Calories, which is the best he can do with
these options.

Cals={123,234,345,162,273,347,992}
maxCal=2000
Result=1969

Cals={250,250,250,250,250,250,250}
maxCal=1600
Result=1500

Cals={1000,400,300,200,100}
maxCal=1600
Result=1600

Cals={100,200,300}
maxCal=1500
Result=600

Definition

Class:
Diet
Method:
maxCal
Parameters:
int[], int
Returns:
int
Method signature:
int maxCal(int[] param0, int param1)
(be sure your method is public)

Constraints

    Examples


      This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
      This problem was used for: