Statistics

Problem Statement for "Sums"

Problem Statement

PROBLEM STATEMENT:

Given a list of numbers (values), and a positive number (howMany), return the
smallest value which is the sum of "howMany" numbers of the list.

Class Name: Sums 
Method Name: minimalSum
Parameters: int[], int
Returns: int 

Method Signature: (be sure your method is public)

int minimalSum(int[] values, int howMany)

TopCoder will ensure the validity of the inputs.  Inputs are valid if all of
the following criteria are met:
  *values contains between 1 and 10 elements, inclusive.
  *howMany is between 1 and the number of elements in values, inclusive.
  *each element of values is between -1000 and 1000, inclusive.

Example 1:
  values: { 5,2,1,4,3 }
  howMany: 3

  3 + 1 + 2 is the minimum sum, so return 6.

Example 2:
  values: { -1,10,10,9,0 }
  howMany: 1

  -1 is the minimum sum, so return -1.

Example 3:
  values: { -1,1,-1,1,0 }
  howMany: 3

  -1 + -1 + 0 is the minimum sum, so return -2.

Example 4:
  values: { -1,1,-1,1,0 }
  howMany: 5

  -1 + -1 + 0 + 1 + 1 is the only sum, so return 0.

Definition

Class:
Sums
Method:
minimalSum
Parameters:
int[], int
Returns:
int
Method signature:
int minimalSum(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: