// Learn more about F# at http://fsharp.org

open System

type S =
    { X: int
      V: int
      W: int64 }

let min a b =
    if a < b then a else b

let max a b =
    if a > b then a else b

[<EntryPoint>]
let main argv =
    let [| n; v; l |] = stdin.ReadLine().Split() |> Array.map int

    let mutable stands =
        [| for i in 1 .. n ->
            (let [| x; v; w |] = stdin.ReadLine().Split() |> Array.map int
             { X = x
               V = v
               W = w |> int64 }) |]
    if stands.[0].X > 0 then
        stands <-
            Array.append
                [| { X = 0
                     V = 0
                     W = 0 |> int64 } |] stands
    if stands.[stands.Length - 1].X < l then
        stands <-
            Array.append stands
                [| { X = l
                     V = 0
                     W = 0 |> int64 } |]
    let nn = stands.Length
    let inf = Int64.MaxValue / 2L
    let mutable memo = Array2D.create (nn + 1) (v + 1) inf
    // printfn "%A" stands
    let rec solve i j =
        // printfn "%A %A" i j
        if memo.[i, j] < inf then
            memo.[i, j]
        else if i = 0 then
            memo.[i, j] <- if j = v then 0L else inf
            memo.[i, j]
        else
            let mutable res = inf
            let d = stands.[i].X - stands.[i - 1].X
            if j + d <= v then res <- min res (solve (i - 1) (j + d))
            for k = (j - 1) downto (max 0 (j - stands.[i].V)) do
                res <- min res ((solve i k) + stands.[i].W)
            memo.[i, j] <- res
            memo.[i, j]

    let mutable ans = inf
    for j = 0 to v do
        ans <- min ans (solve (nn - 1) j)
    if ans < inf then printfn "%d" ans else printfn "-1"
    // printfn "%A" memo
    // printfn "%A" stands
    0 // return an integer exit code