#K75522. Taco Ingredient Quality Evaluation
Taco Ingredient Quality Evaluation
Taco Ingredient Quality Evaluation
In this problem, you are given a list of integer scores representing the quality of ingredients in a taco. You need to calculate the sum of a contiguous subset of these scores. Specifically, if you are given a starting index (s) and a length (l), you must compute the sum of the elements from index (s) to (s+l-1). If the starting index or the length is invalid (i.e., if (s < 0), (l \le 0), or (s+l > n), where (n) is the number of scores), then output (-1).
Example: For the scores array: [7, 1, 5, 9, 6, 3, 2, 8], when (s = 2) and (l = 4), the subarray is [5, 9, 6, 3] and the output is 23.
inputFormat
The input consists of three lines:
- The first line contains space-separated integers representing the scores of taco ingredients.
- The second line contains a single integer, the starting index (s).
- The third line contains a single integer, the desired length (l).
All indices are 0-indexed.
outputFormat
Output a single integer on stdout. This integer is the sum of the scores from index (s) to (s+l-1) if the indices are valid. If any of the conditions fail (invalid start or length), print (-1).## sample
7 1 5 9 6 3 2 8
2
4
23
</p>