The Robot Chef's Kitchen
View as PDFThe Robot Chef's Kitchen
Chef-Bot picks exactly ingredients from either end of a row of ingredients.i.e. you robot can take an ingredient either from the left end or from the right end as needed. However any such split should total to exactly
.
Each ingredient has a tastiness score which can vary between ingredients and can also be negative. Your goal is to write an algorithm to maximize the tastiness score so that robot can work independently.
The Task
Given ingredients and integer
, find the maximum total tastiness by
taking some from the left end and the rest from the right end (total =
).
Input Specification
The first line contains — the number of dishes.
Each dish is defined by two lines:
Line 1: two integers
and
Line 2:
space-separated integers (tastiness scores for the ingredients)
Output Specification
- For each dish print one line of outpu: the maximum total tastiness score
- There would be
lines of output
Sample Input
2
6 4
1 12 -5 -6 50 3
5 3
10 2 3 1 8
Sample Output
66
20
Constraints
Comments