//0:実行モード
//1:開発モード
//2:最終テストモード
const sys_debugMode : number = 0;

function chk(in_data1 : any, in_data2? : any) : void{
	if (sys_debugMode == 0 || sys_debugMode == 2){
		return;
	}
	else if (in_data2 === undefined){
		console.log(in_data1);
	}
	else{
		console.log(in_data1 + "[" + typeof(in_data2) + "] =", in_data2);
	}
}

function prt(in_data : any) : void{
	console.log(in_data);
}

class ParamManager {

	private a_s_inputLines : string[];
	private n_maxLine : number;
	private n_nowLineCnt : number;

	constructor(){
		this.a_s_inputLines = this.inputLines();
		this.n_maxLine = this.a_s_inputLines.length;
		this.descLines();
		this.n_nowLineCnt = 1;
	}
	inputLines(){
		const fs = require('fs');

		let text;
		if(sys_debugMode == 0){
			text = fs.readFileSync("/dev/stdin", 'utf8');
		}
		else{
			text = fs.readFileSync("input.txt", 'utf8');
		}

		const line:string[] = text.toString().replace(/\r/g, "").split('\n');

		return line;
	}
	descLines(){
		chk("ParamManager.a_s_inputLines", this.a_s_inputLines);
	}
	getNextLine(in_s_type?):any{
		if (this.n_nowLineCnt > this.n_maxLine){
			chk("ParamManager.getNextLine","No Next Line!");
			return;
		}
		const s_returnLine:string = this.a_s_inputLines[this.n_nowLineCnt - 1];

		this.n_nowLineCnt++;
		
		if (in_s_type == "n"){
			return parseInt(s_returnLine);
		}
		else if (in_s_type == "a"){
			return s_returnLine.split(" ");
		}
		else if (in_s_type == "an"){
			const a_s_temp = s_returnLine.split(" ");
			const a_n_temp = a_s_temp.map(function(str){return Number(str)});
			return a_n_temp;
		}
		else if(in_s_type == "s"){
			const aMoji:string[] = s_returnLine.split("");
			return aMoji;
		}
		else if(in_s_type == "sn"){
			const aMoji:string[] = s_returnLine.split("");
			const aNum:number[] = aMoji.map(function(str){return Number(str)});
			return aNum;
		}
		else{
			return s_returnLine;
		}
	}
}
const paramManager = new ParamManager();
//==================================================
//https://atcoder.jp/contests/abc167/tasks/abc167_c
//C - Skill Up
//学びたいアルゴリズムがM個あります。
//最初、各アルゴリズムの理解度は0
//N冊の参考書が売っていました。
//i番目の参考書 ( 1 ≤ i ≤ N ) は  Ci円で売られていて、
//購入して読むことで、各  j  ( 1 ≤ j ≤ M ) について
//j  番目のアルゴリズムの理解度が  A i , j  上がります。
//高橋くんの目標は  M  個すべてのアルゴリズムの理解度を  X  以上にすることです。
//高橋くんが目標を達成することが可能か判定
//可能な場合は目標を達成するのに必要な金額の最小値を計算

//入力はすべて整数
//1 ≤ N , M ≤ 12
//1 ≤ X ≤ 10^5
//1 ≤ Ci ≤ 10^5
//0 ≤ A i , j ≤ 10^5
//==================================================
class Param{
	sankoushoNum:number;
	arugorizumuNum:number;
	rikaido:number;

	constructor(){
		chk("--------------------------------------------------");
		chk("パラメータ");
		const aTemp = paramManager.getNextLine("an");
		//N冊の参考書
		//1 ≤ N , M ≤ 12
		this.sankoushoNum = aTemp[1-1];
		//学びたいアルゴリズムM個
		//1 ≤ N , M ≤ 12
		this.arugorizumuNum = aTemp[2-1];
		//すべてのアルゴリズムの理解度をX以上
		//1 ≤ X ≤ 10^5
		this.rikaido = aTemp[3-1];

		chk(this);
	}
}
const param = new Param();
//==================================================
class Sankousho{
	no:number;
	price:number;
	aRikaidoUp:number[];

	constructor(inNo:number){
		this.no = inNo;
		this.aRikaidoUp = [];
	}
}
//==================================================
class Kumiawase{
	no:number;
	aSankoushoNo:number[];
	totalSankoushoPrice:number;
	bSuccess:boolean;

	constructor(inNo:number){
		this.no = inNo;
		this.aSankoushoNo = [];
		this.totalSankoushoPrice = 0;
		this.bSuccess = false;
	}
}
//==================================================
class Manager{
	aSankousho:Sankousho[];
	aKumiawase:Kumiawase[];

	constructor(){
		this.aSankousho = [];
		this.aKumiawase = [];

		this.main();
	}

	main():void{
		chk("--------------------------------------------------");
		chk("main");

		this.makeSankousho();
		this.makeKumiawase();
		this.kumiawaseCheck();
		this.resultOutput();
	}

	kumiawaseCheck(){
		chk("--------------------------------------------------");
		chk("kumiawaseCheck");

		//組み合わせループ
		for (const loopKumiawase of this.aKumiawase) {
			chk("==================================================");
			chk("loopKumiawase",loopKumiawase);

			//アルゴリズム理解度ワーク
			const aWorkArugorizumuRikaido:number[] = Array(param.arugorizumuNum).fill(0);
			//chk("aArugorizumuRikaido",aArugorizumuRikaido);

			//組み合わせ参考書ループ
			for (const loopSankoushoNo of loopKumiawase.aSankoushoNo) {
				//参考書
				const sankousho = this.aSankousho.find(item => {
					return item.no == loopSankoushoNo
				});
				chk("sankousho",sankousho);

				//参考書代加算
				loopKumiawase.totalSankoushoPrice += sankousho.price;

				//アルゴリズム理解度加算
				//アルゴリズム番号ループ
				for(let loopArugorizumuNo = 1 ; loopArugorizumuNo <= param.arugorizumuNum ; loopArugorizumuNo++){
					//アルゴリズム理解度加算
					aWorkArugorizumuRikaido[loopArugorizumuNo-1] += sankousho.aRikaidoUp[loopArugorizumuNo-1];
				}
				chk("aWorkArugorizumuRikaido",aWorkArugorizumuRikaido);
			}

			//全アルゴリズム習得成功フラグ
			let bAllSuccess:boolean = true;
			//習得到達度チェック
			breakPoint:
			for(let loopArugorizumuNo = 1 ; loopArugorizumuNo <= param.arugorizumuNum ; loopArugorizumuNo++){
				//対象アルゴリズムが必要理解度を下回っている場合
				if(aWorkArugorizumuRikaido[loopArugorizumuNo-1] < param.rikaido){
					//全アルゴリズム習得成功フラグOFF
					bAllSuccess = false;
					break breakPoint;
				}
			}
			//全アルゴリズム習得成功の場合
			if(bAllSuccess == true){
				chk("全アルゴリズム習得成功！！！！！");
				//組み合わせオブジェクト　成功フラグON
				loopKumiawase.bSuccess = true;
			}
			else{
				chk("習得失敗");
			}
		}

		chk(this.aKumiawase);
	}

	makeKumiawase():void{
		chk("--------------------------------------------------");
		chk("makeKumiawase");

		//参考書数ループ
		for(let loopSankoushoNum = 1; loopSankoushoNum <= param.sankoushoNum ; loopSankoushoNum++){
			//順列作成
			const aaJunretu = this.kumiawaseChoufukuNashi(param.sankoushoNum, loopSankoushoNum);
			//chk("aaJunretu",aaJunretu);

			//順列ループ
			for (const loopJunretu of aaJunretu) {
				//組み合わせオブジェクト作成
				const k = new Kumiawase(this.aKumiawase.length + 1);
				//組み合わせセット
				k.aSankoushoNo = loopJunretu;
				//組み合わせオブジェクト登録
				this.aKumiawase.push(k);
			}
		}
		//chk(this.aKumiawase);
	}

	kumiawaseChoufukuNashi(in_baseNumMax:number, in_pickupNum:number):number[][]{
		const targetAry: number[] = [];
		for(let loopMaxMaisu = 1 ; loopMaxMaisu <= in_baseNumMax ; loopMaxMaisu++){
			targetAry.push(loopMaxMaisu);
		}
		const wordCount: number = in_pickupNum;

		const presetArys: number[][] = [];  
		let answerArys: number[][] = [];  
		
		const preset = ():void => {  
			targetAry.forEach(target => {  
				presetArys.push([target]);  
			})  
		}  
		
		const setAnswerArys = (nextAnswerArys: number[][], wordCount: number): void => {  
			if (wordCount !== 1) {  
				nextAnswerArys.forEach(answerAry => {  
					for (let i = targetAry.indexOf(answerAry[answerAry.length -1]) + 1; i < targetAry.length; i++){  
						const copyAnswerAry: number[] = answerAry.slice();  
						copyAnswerAry.push(targetAry[i]);  
						if (copyAnswerAry.length < wordCount) {  
							setAnswerArys([copyAnswerAry], wordCount);  
						} else {  
							answerArys.push(copyAnswerAry);  
						}  
					}  
				})  
			} else {   
				answerArys = presetArys;  
			}  
		}  
		
		preset();  
		setAnswerArys(presetArys, wordCount);  

		return answerArys;
	}

	makeSankousho():void{
		chk("--------------------------------------------------");
		chk("makeSankousho");
		//i番目の参考書 ( 1 ≤ i ≤ N )は
		//Ci円で売られていて、
		//j番目のアルゴリズムの理解度がj上がります。
		//1 ≤ Ci ≤ 10^5
		//0 ≤ A i , j ≤ 10^5

		for(let loopSankoushoNo = 1 ; loopSankoushoNo <= param.sankoushoNum ; loopSankoushoNo++){
			const aTemp = paramManager.getNextLine("an");

			const s = new Sankousho(loopSankoushoNo);
			s.price = aTemp[1-1];

			const aRikaidoUp:number[] = aTemp.slice(1);
			//chk("aRikaidoUp",aRikaidoUp);
			s.aRikaidoUp = aRikaidoUp;

			this.aSankousho.push(s);
		}

		chk(this.aSankousho);
	}

	resultOutput():void{
		chk("--------------------------------------------------");
		chk("resultOutput");

		//成功組み合わせ配列
		const aSuccessKumiawase:Kumiawase[] = this.aKumiawase.filter(item => {
			return item.bSuccess == true;
		});
		chk("aSuccessKumiawase",aSuccessKumiawase);

		//高橋くんが目標を達成できないならば -1
		if(aSuccessKumiawase.length == 0){
			prt("-1");
		}
		//そうでなければ目標を達成するのに必要な金額の最小値を出力
		else{
			//成功組み合わせ配列ソート：トータル参考書金額昇順
			const aSortSuccessKumiawase:Kumiawase[] = aSuccessKumiawase.sort((a,b) => {
				return a.totalSankoushoPrice - b.totalSankoushoPrice;
			});
			chk("aSortSuccessKumiawase",aSortSuccessKumiawase);

			const resultKingaku:number = aSortSuccessKumiawase[1-1].totalSankoushoPrice;
			prt(resultKingaku);
		}
	}

}
const manager = new Manager();
//==================================================

Measured memory_bytes: 39764