#P1442D. Sum
Sum
No submission language available for this problem.
Description
You are given non-decreasing arrays of non-negative numbers.
Vasya repeats the following operation times:
- Selects a non-empty array.
- Puts the first element of the selected array in his pocket.
- Removes the first element from the selected array.
Vasya wants to maximize the sum of the elements in his pocket.
The first line contains two integers and (): the number of arrays and operations.
Each of the next lines contain an array. The first integer in each line is (): the size of the -th array. The following integers () are the elements of the -th array.
It is guaranteed that .
Print one integer: the maximum possible sum of all elements in Vasya's pocket after operations.
Input
The first line contains two integers and (): the number of arrays and operations.
Each of the next lines contain an array. The first integer in each line is (): the size of the -th array. The following integers () are the elements of the -th array.
It is guaranteed that .
Output
Print one integer: the maximum possible sum of all elements in Vasya's pocket after operations.