#include"iostream" #include"algorithm" #include"cstring" #include"cstdio" #include"cmath" #include"vector" #include"map" #include"set" #include"queue" usingnamespace std; #define MAXN 200006 //#define int long long #define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i) #define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i) #define pii pair<int,int> #define fi first #define se second #define mp make_pair #define pb push_back #define eb emplace_back #define vi vector<int> #define all(x) (x).begin() , (x).end() #define mem( a ) memset( a , 0 , sizeof a ) typedeflonglong ll; #define P 1000000007 int n , k; vi obs[3006]; ll v[3006] , w[3006];
vector<ll> dp; ll ans = 0; voiddq( int l , int r ){ if( l == r ) { int t = 0; ll r = 0; for( int x : obs[l] ) { ++ t; r += x; ans = max( ans , dp[k - t] + r ); if( t >= k ) break; } return; } vector<ll> tmp = dp; int mid = l + r >> 1; rep( i , l , mid ) { for( int j = k ; j >= v[i] ; -- j ) dp[j] = max( dp[j] , dp[j - v[i]] + w[i] ); } dq( mid + 1 , r ); dp = tmp; rep( i , mid + 1 , r ) { for( int j = k ; j >= v[i] ; -- j ) dp[j] = max( dp[j] , dp[j - v[i]] + w[i] ); } dq( l , mid ); }
voidsolve( ){ cin >> n >> k; rep( i , 1 , n ) { staticint t; scanf("%d",&t); obs[i].resize( t ); rep( j , 0 , t - 1 ) scanf("%d",&obs[i][j]) , w[i] += obs[i][j]; v[i] = t; } dp.resize( k + 1 ); dq( 1 , n ); cout << ans << endl; }