import std; void main(){ auto a = readln.split.to!(int[]); int N = a[0]; int I = a[1]; int[] S; int[] A; for(auto n = 0; n < N; n++){ a = readln.split.to!(int[]); S ~= a[0]; A ~= a[1]; } int[] prev = new int[I + 1]; prev[] = int.min; prev[0] = 0; for(auto n = 0; n < N; n++){ int[] next = prev.dup; for(auto i = 0; i + S[n] <= I; i++){ next[i + S[n]] = max(next[i + S[n]], prev[i] + A[n]); } prev = next; } writeln(prev.maxElement); }