Scanf.scanf "%d %d %d" (fun n m x ->
    let c = Array.make n 0 in
    let a = Array.make_matrix n m 0 in
    for i = 0 to n - 1 do
        Scanf.scanf " %d" (fun cx -> c.(i) <- cx);
        for j = 0 to m - 1 do
            Scanf.scanf " %d" (fun ax -> a.(i).(j) <- ax);
        done
    done;

    let calc bit =
        let skills = Array.make m 0 in
        let rec loop i acc =
            if i = n then acc else
            let acc = if bit land (1 lsl i) > 0 then (
                for j = 0 to m - 1 do
                    skills.(j) <- skills.(j) + a.(i).(j)
                done;
                acc + c.(i)
            ) else acc
            in
            loop (i + 1) acc
        in
        let cost = loop 0 0 in
        if Array.fold_left (fun acc v -> if v >= x then acc else false) true skills then cost else -1
    in

    let rec loop i acc =
        if i < 0 then acc else
            let cost = calc i in
            let acc = if cost >= 0 then min acc cost else acc in
            loop (i - 1) acc
    in
    let ans = loop ((1 lsl n) - 1) max_int in
    Printf.printf "%d\n" @@ if ans = max_int then -1 else ans
)