Codeforces Round 681 (Div. 1, based on VK Cup 2019-2020 - Final)
D
Sum
Codeforces
2800
原题
← CE →
翻译中…

You are given $n$ non-decreasing arrays of non-negative numbers.

翻译中…

Vasya repeats the following operation $k$ 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.

翻译中…

Input

翻译中…

The first line contains two integers $n$ and $k$ ($1 \le n, k \le 3\,000$): the number of arrays and operations.

翻译中…

Each of the next $n$ lines contain an array. The first integer in each line is $t_i$ ($1 \le t_i \le 10^6$): the size of the $i$-th array. The following $t_i$ integers $a_{i, j}$ ($0 \le a_{i, 1} \le \ldots \le a_{i, t_i} \le 10^8$) are the elements of the $i$-th array.

翻译中…

It is guaranteed that $k \le \sum\limits_{i=1}^n t_i \le 10^6$.

翻译中…

Output

翻译中…

Print one integer: the maximum possible sum of all elements in Vasya's pocket after $k$ operations.

翻译中…

样例

Input #1
3 3
2 5 10
3 1 2 3
2 1 20
Output #1
26
InputCopy OutputCopy
题目信息
题号
1442D
时间限制
1.5 s
内存限制
512 MB
标签
数据结构
分治
动态规划
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。