local mmi, mma = math.min, math.max local n, v, c = io.read("*n", "*n", "*n") local t = {} for i = 1, v do t[i] = 0 end for i = 1, n do local a, b = io.read("*n", "*n") for j = v - a, 1, -1 do t[j + a] = mma(t[j + a], t[j] + b + c) end if a <= v then t[a] = mma(t[a], b + c) end for j = 1, v - a do t[j + a] = mma(t[j + a], t[j] + b) end end print(t[v])