import java.util.*; classthing{ int v;//体积 int w;//价值 publicthing(int v,int w){ this.v = v; this.w = w; } } publicclassMain{ publicintsolve(int N,int V,ArrayList<ArrayList<thing>> list){ int[] dp = newint[V + 1]; for (int i = 0; i < N; i++) { ArrayList<thing> sub = list.get(i); for (int j = V; j >= 0; j--) { for (int k = 0; k < sub.size(); k ++) { thing t = sub.get(k); if (j - t.v >= 0) { dp[j] = Math.max(dp[j],dp[j - t.v] + t.w); } } } //show(dp); } return dp[dp.length - 1]; } publicstaticvoidshow(int[] arr){ for (int i = 0; i <arr.length; i++) { System.out.print(arr[i]+" "); } System.out.println("*"); } publicstaticvoidmain(String[] args){ Scanner sc = new Scanner(System.in); Main main = new Main(); int N = sc.nextInt(); int V = sc.nextInt(); ArrayList<ArrayList<thing>> list = new ArrayList<>(N); for (int index = 0; index < N; index ++) { int s = sc.nextInt(); ArrayList<thing> sub = new ArrayList<>(s); thing th = null; for (int i = 0; i < s; i ++) { int v = sc.nextInt(); int w = sc.nextInt(); th = new thing(v,w); sub.add(th); } list.add(sub); } System.out.println(main.solve(N,V,list)); } }