const main = input => {
  const [[N, M, X], ...list] = input.map(e => e.map(Number))
  const books = list.map(([C, ...As]) => [C, As])

  const add = (us, book) => us.map((A, i) => A + book[1][i])
  const check = us => us.every(e => e >= X)
  const sum = arr => arr.reduce((p, v) => p + v, 0)

  const sorted = [...books].sort((a, b) => sum(b[1]) - sum(a[1]))

  const Csum = (def => (
    def((fn, [book, ...rest], Csum, us) => (
      !book
        ? -1
        : check(us)
          ? Csum
          : fn(fn, rest, Csum + book[0], add(us, book))
    ),
    fn => fn(fn, sorted, 0, Array(M).fill(0)))
  ))(((val, cb) => cb(val)))

  return [[Csum]]
}

const wrapper = data => {
  const input = data.trim().split('\n').map(line => line.split(' '))
  const output = main(input)
  console.log(output.map(line => line.join(' ')).join('\n'))
}

wrapper(require('fs').readFileSync('/dev/stdin', 'utf8'))
