#include using namespace std; int main(){ ios::sync_with_stdio(false); int n,m, x; vector> shelfs, optansw, prefs, tabulardp; cin >> n >> m; shelfs.assign(n, vector()); prefs.assign(n, vector()); optansw.assign(n, vector(101, 0)); for(int i = 0; i < n; i++){ cin >> x; shelfs[i].resize(x); prefs[i].resize(x+1); prefs[i][0] = 0; for(int j = 0; j < x; j++){ cin >> shelfs[i][j]; prefs[i][j+1] = prefs[i][j] + shelfs[i][j]; } } for(int i = 0; i < n; i++){ optansw[i][shelfs[i].size()] = prefs[i][shelfs[i].size()]; for(int l = 0; l < shelfs[i].size(); l++){ for(int r = l; r < shelfs[i].size(); r++){ optansw[i][shelfs[i].size() - (r-l+1)] = max(optansw[i][shelfs[i].size() - (r-l+1)], prefs[i][shelfs[i].size()] - prefs[i][r+1] + prefs[i][l]); } } for(int l = shelfs[i].size()+1; l < 101; l++){ optansw[i][l] = optansw[i][l-1]; } } tabulardp.assign(n+1, vector(m+1, 0)); for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++){ // Descendo inicialmente j e pegando opt[0] int stop = min(100, j); for(int k = 0; k <= stop; k++){ tabulardp[i][j] = max(tabulardp[i][j], tabulardp[i-1][j-k] + optansw[i-1][k]); } } } cout << tabulardp[n][m] << '\n'; return 0; }