PROBLEM STATEMENT
You are trying to eat more healthy meals. You know the nutritional information
of each of the food items you can eat. This information contains the number of
calories in each food item, and the vitamin content of each item - represented
as the percentage of the recommended amounts of each of 3 vitamins.
Create a class LightMeal which contains a method calories that, given a
String[] of food items' dietary information, returns the number of calories in
the meal you should eat that contains the fewest calories and that provides at
least 100 percent of each of these three vitamins.
DEFINITION
Class: LightMeal
Method: calories
Parameters: String[]
Returns: int
Method signature (be sure your method is public): int calories(String[] items);
Each element in items will be in the form of "<CALORIES> <VITAMIN A> <VITAMIN
B> <VITAMIN C>" (quotes are for clarity only). <CALORIES> represents the
number of calories in the item. <VITAMIN A>, <VITAMIN B>, and <VITAMIN C> each
represent the percent of the recommended amount of each vitamin the item
contains.
NOTES
- Meals with more than 100 percent of one or more vitamins are fine. Your
concern is only to find the meal with at least 100 percent of each vitamin and
the minimum number of calories.
- You can not eat part of an item, nor can you eat more than one of each item.
You must either eat the entire single item, or none of it.
TopCoder will ensure the validity of the inputs. Inputs are valid if all of
the following criteria are met:
- String[] items will contain between 1 and 20 elements, inclusive.
- Each element of String[] items will be between 7 and 50 characters in length,
inclusive.
- Each element of String[] items will contain 4 non-negative integers each
separated by a single space. Each of these numbers will be between 0 and 1000,
inclusive. Each of these numbers can contain leading zeros.
- Each element of items will contain only digits '0'-'9' and spaces ' '.
- Each element of String[] items will neither start nor end with a space.
- There will be at least one combination of items that will provide at least
100% of each of the 3 vitamins.
EXAMPLES
In each of these examples, quotes ('"'), commas (','), and curly braces ('{'
and '}') are included for clarity only. They are never part of the input or
output.
Example #1:
items = {"100 100 100 100"}
return: 100
There is only one food item, and it provides at least 100% of each of the three
vitamins. It consists of 100 calories, so return 100.
Example #2:
items = {"1 5 5 5", "1 5 5 5", "1 5 5 5", "1 5 5 5", "1 5 5 5", "1 5 5 5", "1 5
5 5", "1 5 5 5", "1 5 5 5", "1 5 5 5", "1 5 5 5", "1 5 5 5", "1 5 5 5", "1 5 5
5", "1 5 5 5", "1 5 5 5", "1 5 5 5", "1 5 5 5", "1 5 5 5", "1 5 5 5"}
return: 20
All items must be eaten to get 100 percent of each vitamin.
Example #3:
items = {"10 100 0 0", "20 0 100 0", "40 0 0 100", "80 100 100 100", "160 0 0 0"}
return: 70
The lowest-calorie combination that contains the required vitamins includes
just the first three items ("10 100 0 0", "20 0 100 0", and "40 0 0 100").
Example #4:
items = {"100 100 100 100", "50 1000 1000 1000", "10 100 100 99"}
return: 50
The lowest-calorie combination that contains the required vitamins includes
only the second item ("50 1000 1000 1000").
Example #5:
items = {"0 100 0 0", "0 0 100 0", "10 0 0 100", "0 0 0 100"}
return: 0
Example #6:
items = {"20 20 20 20", "20 20 20 20", "20 20 20 20", "20 20 20 20", "20 20 20
20", "20 20 20 20", "20 20 20 20", "20 20 20 20", "20 20 20 20", "20 20 20 20",
"20 20 20 20", "20 20 20 20", "20 20 20 20", "20 20 20 20", "20 20 20 20", "20
20 20 20", "20 20 20 20", "20 20 20 20", "20 20 20 20", "20 20 20 20"}
return: 100