Scanf.scanf "%d %d" (fun n t ->
    let dp = Array.make (t + 1) 0 in
    for i = 1 to n do
        Scanf.scanf " %d %d" (fun a b ->
            for j = t - 1 downto 0 do
                let idx = min t (j + a) in
                dp.(idx) <- max dp.(idx) (dp.(j) + b)
            done
        )
    done;
    Array.fold_left max 0 dp |> Printf.printf "%d\n"
)