Scanf.scanf "%d %d" (fun n t ->
    let ab = Array.init n (fun _ -> Scanf.scanf " %d %d" (fun a b -> a, b)) in
    Array.sort compare ab;
    let dp = Array.make (t + 1) 0 in
    Array.iter (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
    ) ab;
    Array.fold_left max 0 dp |> Printf.printf "%d\n"
)