local mmi, mma = math.min, math.max local n, v, l = io.read("*n", "*n", "*n") local dp = {} for i = 1, v + 1 do dp[i] = false end dp[v + 1] = 0 local pos = 0 for i = 1, n do local x, z, w = io.read("*n", "*n", "*n") -- walk local len = x - pos for j = len + 1, v + 1 do dp[j - len] = dp[j] end for j = v + 1 - len + 1, v + 1 do dp[j] = false end -- add for j = v, 1, -1 do if dp[j] then local dst = mmi(v + 1, j + z) if not dp[dst] then dp[dst] = dp[j] + w else dp[dst] = mmi(dp[dst], dp[j] + w) end end end pos = x end do local len = l - pos for j = len + 1, v + 1 do dp[j - len] = dp[j] end for j = v + 1 - len + 1, v + 1 do dp[j] = false end end local ret = false for i = 1, v + 1 do if dp[i] then if not ret then ret = dp[i] else ret = mmi(ret, dp[i]) end end end print(ret or -1)