#include <bits/stdc++.h>
using namespace std;

#define SIZE_OF_ARRAY(array) sizeof(array)/sizeof(array[0])

struct book{
    int m;
    vector<int> v;
};
int main() {
    int N, M, X;
    cin >> N >> M >> X;
    vector<book> books;
    for(int i = 0; i < N; i++){
        int C;
        cin >> C;
        vector<int> l;
        for(int j = 0; j < M;j++){
            int A;
            cin >> A;
            l.push_back(A);
        }
        books.push_back({C,l});
    }
    for(int i = 0; i < 12-N; i++){
        vector<int> l;
        for(int j = 0; j < M; j++){
            l.push_back(0);
        }
        books.push_back({0,l});
    }
    int minmon = (books.at(0).m) + (books.at(1).m) + (books.at(2).m) + (books.at(3).m)
                + (books.at(4).m) + (books.at(5).m) + (books.at(6).m) + (books.at(7).m)
                + (books.at(8).m) + (books.at(9).m) + (books.at(10).m) + (books.at(11).m);
    bool whi = false;
    for(int a = 0; a <= 1; a++){
        for(int b = 0; b <= 1; b++){
            for(int c = 0; c <= 1; c++){
                for(int d = 0; d <= 1; d++){
                    for(int e = 0; e <= 1; e++){
                        for(int f = 0; f <= 1; f++){
                            for(int g = 0; g <= 1; g++){
                                for(int h = 0; h <= 1; h++){
                                    for(int i = 0; i <= 1; i++){
                                        for(int j = 0; j <= 1; j++){
                                            for(int k = 0; k <= 1; k++){
                                                for(int l = 0; l <= 1; l++){
                                                    bool w = true;
                                                    int money = (books.at(0).m)*a + (books.at(1).m)*b + (books.at(2).m)*c + (books.at(3).m)*d
                                                                + (books.at(4).m)*e + (books.at(5).m)*f + (books.at(6).m)*g + (books.at(7).m)*h
                                                                + (books.at(8).m)*i + (books.at(9).m)*j + (books.at(10).m)*k + (books.at(11).m)*l;
                                                    for(int ind = 0; ind < M; ind++){
                                                        int alg = (books.at(0).v.at(ind))*a + (books.at(1).v.at(ind))*b + (books.at(2).v.at(ind))*c + (books.at(3).v.at(ind))*d
                                                                + (books.at(4).v.at(ind))*e + (books.at(5).v.at(ind))*f + (books.at(6).v.at(ind))*g + (books.at(7).v.at(ind))*h
                                                                + (books.at(8).v.at(ind))*i + (books.at(9).v.at(ind))*j + (books.at(10).v.at(ind))*k + (books.at(11).v.at(ind))*l;
                                                        if(alg < X){
                                                            w = false;
                                                            break;
                                                        }
                                                    }
                                                    if(w && (minmon >= money)){
                                                        whi = true;
                                                        minmon = money;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if(whi){
        cout << minmon;
    } else {
        cout << -1;
    }
}

Measured memory_bytes: 3608