stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



#define MX 100050

#define INF 0x7f7f7f7f7f7f7f7fll

typedef long long ll;

struct edge {

	int v; ll w;

	edge(int v = 0, ll w = 0) : v(v), w(w) {}

	bool operator < (const edge& rhs) const { return w > rhs.w; }

};



vector<edge> g[MX];

ll d[MX];

bool vis[MX];



int main() {

	int n, m;

	scanf("%d%d", &n, &m);

	for(int i = 2; i <= n; i++) g[i].push_back(edge(i - 1, 0));

	while(m--) {

		int l, r, c;

		scanf("%d%d%d", &l, &r, &c);

		g[l].push_back(edge(r, c));

	}

	priority_queue<edge> pq;

	pq.push(edge(1, 0));

	for(int i = 2; i <= n; i++) d[i] = INF;

	

	while(pq.size()) {

		edge e = pq.top(); pq.pop();

		int u = e.v;

		if(vis[u]) continue;

		vis[u] = true;

		

		for(auto e : g[u])

			if(d[e.v] > d[u] + e.w) {

				d[e.v] = d[u] + e.w;

				pq.push(edge(e.v, d[e.v]));

			}

	}

	if(d[n] == INF) puts("-1");

	else printf("%lld\n", d[n]);

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.2655637426910913x):
#include <bits/stdc++.h>

using namespace std;



const int N = 220000;



int L[N], R[N], id[N];

long long C[N], t[N];



void add(int u, long long w) {

	for (; u; u -= u & -u) t[u] = min(t[u], w);

}



long long get(int u) {

	long long ret = LLONG_MAX;

	for (; u < N; u += u & -u) ret = min(ret, t[u]);

	return ret;

}



int main() {

	ios::sync_with_stdio(0);

	cin.tie(0); cout.tie(0);

	int n, m; cin >> n >> m;

	for (int i = 0; i < m; i++) cin >> L[i] >> R[i] >> C[i];

	for (int i = 0; i < m; i++) id[i] = i;

	sort(id, id + m, [&](int u, int v) {

		if (L[u] != L[v]) return L[u] < L[v];

		return R[u] < R[v];

	});

	for (int i = 0; i < N; i++) t[i] = LLONG_MAX;

	add(1, 0);

	for (int i = 0; i < m; i++) {

		int u = id[i];

		int st = L[u], en = R[u]; long long w = C[u];

		long long now = get(st);

		if (now != LLONG_MAX) add(en, now + w);

	}

	long long ans = get(n);

	if (ans == LLONG_MAX) ans = -1;

	cout << ans << "\n";

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



const int N = 110000;

const long long INF = 1LL << 60;



int L[N], R[N], C[N];

long long val[N];



vector<int> st[N], en[N];



set<pair<long long, int>> S;



int main() {

	

	ios::sync_with_stdio(0);

	cin.tie(0), cout.tie(0);

	

	int n, m; cin >> n >> m;

	for (int i = 1; i <= m; i++) {

		cin >> L[i] >> R[i] >> C[i];

		st[L[i]].push_back(i);

		en[R[i]].push_back(i);

	}

	

	for (int i = 1; i <= n; i++) val[i] = INF;

	val[1] = 0;

	for (int i = 1; i <= n; i++) {

		if (S.size()) val[i] = min(val[i], S.begin() -> first);

		for (auto it : st[i]) S.emplace(val[L[it]] + C[it], it);

		for (auto it : en[i]) S.erase(make_pair(val[L[it]] + C[it], it));

	}

	if (val[n] == INF) cout << "-1\n";

	else cout << val[n] << "\n";

	

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 2.532584577781535x):
#include <bits/stdc++.h>

using namespace std;



const int N = 220000;



int L[N], R[N], id[N];

long long C[N], t[N];



void add(int u, long long w) {

	for (; u; u -= u & -u) t[u] = min(t[u], w);

}



long long get(int u) {

	long long ret = LLONG_MAX;

	for (; u < N; u += u & -u) ret = min(ret, t[u]);

	return ret;

}



int main() {

	ios::sync_with_stdio(0);

	cin.tie(0); cout.tie(0);

	int n, m; cin >> n >> m;

	for (int i = 0; i < m; i++) cin >> L[i] >> R[i] >> C[i];

	for (int i = 0; i < m; i++) id[i] = i;

	sort(id, id + m, [&](int u, int v) {

		if (L[u] != L[v]) return L[u] < L[v];

		return R[u] < R[v];

	});

	for (int i = 0; i < N; i++) t[i] = LLONG_MAX;

	add(1, 0);

	for (int i = 0; i < m; i++) {

		int u = id[i];

		int st = L[u], en = R[u]; long long w = C[u];

		long long now = get(st);

		if (now != LLONG_MAX) add(en, now + w);

	}

	long long ans = get(n);

	if (ans == LLONG_MAX) ans = -1;

	cout << ans << "\n";

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;

typedef long long ll;



#define rep(i, N) for (int i = 0; i < (int)N; i++)

const ll MOD = pow(10,9)+7;

const ll LLINF = pow(2,61)-1;

const int INF = pow(2,30)-1;





#define P pair<ll, ll>

const int N_MAX = pow(10,5)+10;

struct edge { ll to; ll cost; };

vector<edge> adj[N_MAX], radj[N_MAX];



ll d[N_MAX];

ll N, M, T;



void dijkstra(ll s) {

  priority_queue<P, vector<P>, greater<P>> q;

  fill_n(d, N, LLINF); d[s] = 0; q.push(P(0, s));

  while (!q.empty()) {

    P p = q.top(); q.pop();

    ll v = p.second;

    if (d[v] < p.first) continue;

    for (auto e: adj[v]) {

      if (d[e.to] > d[v]+e.cost) {

        d[e.to] = d[v]+e.cost;

        q.push(P(d[e.to], e.to));

      }

    }

  }

}



int main() {

  cin >> N >> M;

  rep(i,M) {

    int L, R, C; cin >> L >> R >> C; L--; R--;

    edge tmp = {R, C};

    adj[L].push_back(tmp);

  }

  rep(i,N-1) adj[i+1].push_back((edge){i, 0});

  dijkstra(0);

  ll result = (d[N-1]!=LLINF) ? d[N-1] : -1;

  // rep(i,N) cout << d[i] << " "; cout << endl;

  cout << result << endl;

  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.810537676312697x):
// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。

//





#define _USE_MATH_DEFINES

#include<math.h>



//#include<cmath>



#include<deque>

#include<queue>

#include<vector>

#include<algorithm>

#include<iostream>

#include<set>

#include<cmath>

#include<tuple>

#include<string>

#include<chrono>

#include<functional>

#include<iterator>

#include<random>

#include<unordered_set>

#include<array>

#include<map>

#include<iomanip>

#include<assert.h>

#include<bitset>

#include<stack>

#include<memory>







//#include "Ants.h"

using namespace std;

typedef long long ll;

#define rad_to_deg(rad) (((rad)/2/M_PI)*360)

#define EPS (1e-7)

#define INF (1e9)

#define PI (acos(-1))

#define rep(i,n) for(int i=0;i<n;i++)

#define show(s) cout<<s<<endl

#define chmin(x,y) x=min(x,y)

#define chmax(x,y) x=max(x,y)



typedef pair < ll, ll> P;



const ll LLINF = pow(2, 61) - 1;

ll N, M;

struct edge {

	ll to, cost;

	

};



ll d[10000000];



vector<edge>G[100000];

void dijkstra(ll s) {

	priority_queue<P, vector<P>, greater<P>> q;

	fill_n(d, N, LLINF); d[s] = 0; q.push(P(0, s));

	while (!q.empty()) {

		P p = q.top(); q.pop();

		ll v = p.second;

		if (d[v] < p.first) continue;

		for (auto e : G[v]) {

			if (d[e.to] > d[v] + e.cost) {

				d[e.to] = d[v] + e.cost;

				q.push(P(d[e.to], e.to));

			}

		}

	}

}



int main() {

	cin >> N >> M;

	rep(i, M) {

		int L, R, C; cin >> L >> R >> C; L--; R--;

		edge tmp = { R, C };

		G[L].push_back(tmp);

	}

	rep(i, N - 1) G[i + 1].push_back((edge){i, 0});

	dijkstra(0);

	ll result = (d[N - 1] != LLINF) ? d[N - 1] : -1;

	// rep(i,N) cout << d[i] << " "; cout << endl;

	cout << result << endl;

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

ll tr[4100000];

struct rp {

    int x, y;

    ll z;

} a[110000];

vector<int> v[110000];

int n, m, all;



void getnew(int root) {

    root /= 2;

    while (root) {

        tr[root] = min(tr[root * 2], tr[root * 2 + 1]);

        root /= 2;

    }

}



ll getmin(int l, int r) {

    ll ans = 1e15;

    while (r - l > 1) {

        if (l % 2 == 0)

            ans = min(ans, tr[l + 1]);

        if (r % 2 == 1)

            ans = min(ans, tr[r - 1]);

        l >>= 1, r >>= 1;

    }

    return ans;

}



int main() {

    scanf("%d%d", &n, &m);

    for (int i = 1; i <= m; i++)

        scanf("%d%d%d", &a[i].x, &a[i].y, &a[i].z);

    for (int i = 1; i <= m; i++) {

        v[a[i].y].push_back(i);

    }

    all = 1;

    while (all <= n)

        all <<= 1;

    all--;

    for (int i = 1; i <= all + all + 1; i++)

        tr[i] = 1e15;

    for (int i = 1; i <= m; i++) {

        if (a[i].x == 1) {

            tr[all + a[i].y] = a[i].z;

            getnew(all + a[i].y);

        }

    }

    for (int i = 1; i <= n; i++) {

        for (auto j:v[i]) {

            ll now = getmin(all + a[j].x - 1, all +a[j].y + 1) + a[j].z;

            if (now < tr[all + a[j].y]) {

                tr[all + a[j].y] = now;

                getnew(all + a[j].y);

            }

        }

    }

  //  printf("%lld..\n", tr[all + n]);

    if (tr[all + n] < 1e15) {

        printf("%lld\n", tr[all + n]);

    } else puts("-1");

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 3.7062947926121477x):
#include<iostream>

#include <bits/stdc++.h>

//1000000000000223

#define ll long long

#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

int n, m, l, r, c;

ll t[400009], inf=2e14;

vector<pair<int, pair<int,int> > > v;

void update(int v, int s, int e, int pos,ll val)

{

    if(s==e)

    {

        t[v]=min(t[v],val);

        return ;

    }

    int m=(s+e)/2;

    pos<=m ? update(2*v,s,m,pos,val) : update(2*v+1,m+1,e,pos,val);

    t[v]=min(t[2*v],t[2*v+1]);

}

ll solve(int v, int s, int e, int l, int r)

{

    if(s>r||e<l)

        return inf;

    if(s>=l &&e<=r)

        return t[v];

    int m=(s+e)/2;

    return min(solve(2*v,s,m,l,r),solve(2*v+1,m+1,e,l,r));

}

int main()

{

    IO

    cin>>n>>m;

    while(m--)

    {

        cin>>l>>r>>c;

        v.push_back({l,{r,c}});

    }

    for(int i=1;i<=4*n;i++)

        t[i]=inf;

    sort(v.begin(),v.end());

    if(v[0].first!=1)

        return cout<<-1, 0 ;

    for(auto i : v)

    {

        if(i.first==1)

        {

            update(1,1,n,i.second.first,i.second.second);

            continue;

        }

        ll x=solve(1,1,n,i.first,n);

        update(1,1,n,i.second.first,i.second.second+x);

    }

    ll x=solve(1,1,n,n,n);

    if(x>=inf)

        x=-1;

    cout<<x;



    return 0;

}
// Slower C++ solution:
#include <iostream>

#include <queue>

#include <cstdio>

#include <vector>

typedef long long      ll;

using namespace std;

const int maxn = 1e5 + 10;

typedef pair<ll, ll>   pil;

typedef vector<pil>    vil;

#define pb    push_back

#define mp    make_pair

ll       n, m, dis[maxn], vis[maxn];

const ll inf = 0x3f3f3f3f3f3f3f3f;

struct node

{

    ll d, id;

};

vector<pil> V[maxn];

void init()

{

    for (ll i = 2; i <= n; i++)

        V[i].pb(mp(i - 1, 0));

}

priority_queue<pil, vil, greater<pil> > q;

void solve()

{

    int s = 1;

    for (int i = 1; i <= n; i++)

        dis[i] = inf;

    dis[s] = 0;

    q.push(mp(dis[s], s));

    while (!q.empty())

    {

        pil p   = q.top(); q.pop();

        int mid = p.second;

        if (vis[mid])

            continue;

        vis[mid] = 1;

        for (int i = 0; i < V[mid].size(); i++)

        {

            int y = V[mid][i].first, d = V[mid][i].second;

            if (!vis[y] && dis[mid] + d < dis[y])

            {

                dis[y] = dis[mid] + d;

                q.push(mp(dis[y], y));

            }

        }

    }

    // for (int i = 1; i <= n; i++)

    //     cout << dis[i] << endl;

    if (dis[n] != inf)

        cout << dis[n] << endl;

    else

        cout << "-1\n";

}



int main()

{

    ios::sync_with_stdio(0);

    cin >> n >> m;

    init();

    for (ll i = 0, u, v, w; i < m; i++)

    {

        cin >> u >> v >> w;

        V[u].pb(mp(v, w));

    }

    // for (int i = 1; i <= n; i++)

    // {

    //     for (int j = 0; j < V[i].size(); j++)

    //     {

    //         cout << i << endl;

    //         cout << V[i][j].first << " " << V[i][j].second << endl;

    //     }

    // }

    solve();

}


// Faster C++ solution for the same problem (measured speedup: 3.4975304522921027x):
#include<iostream>

#include <bits/stdc++.h>

//1000000000000223

#define ll long long

#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

int n, m, l, r, c;

ll t[400009], inf=2e14;

vector<pair<int, pair<int,int> > > v;

void update(int v, int s, int e, int pos,ll val)

{

    if(s==e)

    {

        t[v]=min(t[v],val);

        return ;

    }

    int m=(s+e)/2;

    pos<=m ? update(2*v,s,m,pos,val) : update(2*v+1,m+1,e,pos,val);

    t[v]=min(t[2*v],t[2*v+1]);

}

ll solve(int v, int s, int e, int l, int r)

{

    if(s>r||e<l)

        return inf;

    if(s>=l &&e<=r)

        return t[v];

    int m=(s+e)/2;

    return min(solve(2*v,s,m,l,r),solve(2*v+1,m+1,e,l,r));

}

int main()

{

    IO

    cin>>n>>m;

    while(m--)

    {

        cin>>l>>r>>c;

        v.push_back({l,{r,c}});

    }

    for(int i=1;i<=4*n;i++)

        t[i]=inf;

    sort(v.begin(),v.end());

    if(v[0].first!=1)

        return cout<<-1, 0 ;

    for(auto i : v)

    {

        if(i.first==1)

        {

            update(1,1,n,i.second.first,i.second.second);

            continue;

        }

        ll x=solve(1,1,n,i.first,n);

        update(1,1,n,i.second.first,i.second.second+x);

    }

    ll x=solve(1,1,n,n,n);

    if(x>=inf)

        x=-1;

    cout<<x;



    return 0;

}
// Slower C++ solution:
#include <cstdio>

#include <cmath>

#include <complex>

#include <iostream>



#define REP(i,n) for(int i=0; i<(int)(n); i++)



using namespace std;



typedef complex<double> P;



const double PI = 3.1415926535;

P pos[40];

int n, m;

int fst;



double memo[41][41];



inline double outp(const P &a, const P &b){

  return (conj(a)*b).imag();

}



double solve(int p, int rest){

  if(p == n) return 0.0;

  if(rest == 0) return 0.0;

  if(memo[p][rest] > -1.0)

    return memo[p][rest];

  double ret = 0.0;



  for(int i = p + 1; i < n; i++){

    double tmp = 0.0;



    if(rest != m - 1){

      P p1 = pos[fst];

      P p2 = pos[p];

      P p3 = pos[i];

      tmp += std::abs(outp(p2 - p1, p3 - p1) / 2.0);

      // printf("tmp: %f\n", tmp);

    }



    ret = max(ret, tmp + solve(i, rest - 1));

  }



  // printf("%d %d %d: %f\n", fst, p, rest, ret);

  return memo[p][rest] = ret;

}



int main(){

  while(scanf("%d%d", &n, &m), n + m){

    REP(i,n){

      double ang;

      scanf("%lf", &ang);

      pos[i] = P(cos(2 * PI * ang), sin(2 * PI * ang));

      // cout << "pos[" << i << "]=" << pos[i] << endl;

    }



    double ans = 0.0;

    REP(i,n){

      REP(j,n) REP(k,m) memo[j][k] = -2.0;

      fst = i;

      ans = max(ans, solve(i, m - 1));

    }



    printf("%.6f\n", ans);

  }

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.2493118370926797x):
#include <cstdio>

#include <cmath>

#include <complex>

#include <iostream>



#define REP(i,n) for(int i=0; i<(int)(n); i++)



using namespace std;



typedef complex<double> P;



const double PI = 3.1415926535;

P pos[40];

int n, m;

int fst;



double memo[41][41];



inline double outp(const P &a, const P &b){

  return (conj(a)*b).imag();

}



double solve(int p, int rest){

  if(p == n) return 0.0;

  if(rest > n - p) return 0.0;

  if(rest == 0) return 0.0;

  if(memo[p][rest] > -1.0)

    return memo[p][rest];

  double ret = 0.0;



  for(int i = p + 1; i < n; i++){

    double tmp = 0.0;



    if(rest != m - 1){

      P p1 = pos[fst];

      P p2 = pos[p];

      P p3 = pos[i];

      tmp += std::abs(outp(p2 - p1, p3 - p1) / 2.0);

      // printf("tmp: %f\n", tmp);

    }



    ret = max(ret, tmp + solve(i, rest - 1));

  }



  // printf("%d %d %d: %f\n", fst, p, rest, ret);

  return memo[p][rest] = ret;

}



int main(){

  while(scanf("%d%d", &n, &m), n + m){

    REP(i,n){

      double ang;

      scanf("%lf", &ang);

      pos[i] = P(cos(2 * PI * ang), sin(2 * PI * ang));

      // cout << "pos[" << i << "]=" << pos[i] << endl;

    }



    double ans = 0.0;

    REP(i,n){

      REP(j,n) REP(k,m) memo[j][k] = -2.0;

      fst = i;

      ans = max(ans, solve(i, m - 1));

    }



    printf("%.6f\n", ans);

  }

  return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;

ll A[14][14],C[14];

int main()

{

    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);

    ll n,m,x;

    memset(A,0,sizeof(A));

    memset(C,0,sizeof(C));

    cin>>n>>m>>x;

    for(int i=0; i<n; i++)

    {

        cin>>C[i];

        for(int j=0; j<m; j++)

        {

            cin>>A[i][j];

        }

    }

    ll Ans=10000007;

    for(int i=0; i<=4095; i++)

    {

        string s = bitset<12>(i).to_string();

        reverse(s.begin(),s.end());

        ll Cost=0,ul[14];

        memset(ul,0,sizeof(ul));

        for(int j=0; j<n; j++)

        {

            if(s[j]=='0')

                continue;

            Cost+=C[j];

            for(int k=0; k<m; k++)

            {

                ul[k]+=A[j][k];

            }

        }

        bool flag=true;

        for(int j=0; j<m; j++)

        {

            if(ul[j]<x)

                flag=false;

        }

        if(flag==true)

            Ans=min(Ans,Cost);

    }

    if(Ans==10000007)

        cout<<-1<<endl;

    else

        cout<<Ans<<endl;





    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.5013880056744084x):
#include <cstdio>

#include <iostream>

#include <algorithm>

#include <cstring>



using namespace std;



struct node

{

	int c;

	int a[15];

}book[15];



int main()

{

//	freopen("input.txt","r",stdin);

	

	int n,m,x;

	cin>>n>>m>>x;

	for(int i=0;i<n;i++)

	{

		cin>>book[i].c;

		for(int j=0;j<m;j++) cin>>book[i].a[j];

	}

//	for(int i=0;i<n;i++)

//	{

//		cout<<book[i].c<<" ";

//		for(int j=0;j<m;j++) cout<<book[i].a[j];

//		puts("");

//	}

	int ans=-1;

	for(int i=0;i<(1<<n);i++)

	{

		int sum=0;

		int b[m+5];//随机值啊 

		memset(b,0,sizeof b); 

		for(int j=0;j<n;j++)

			if((i>>j)&1)

			{

				sum+=book[j].c;

				for(int k=0;k<m;k++) b[k]+=book[j].a[k];

			}

		bool flag=1;

		for(int j=0;j<m;j++) if(b[j]<x) flag=0;

		if(flag)

		{

			if(ans==-1) ans=sum;

			else ans=min(ans,sum);

		}

	}

	cout<<ans<<endl;

	

	return 0;

 } 

 

//每行第一个数前不输出
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;

ll A[14][14],C[14];

int main()

{

    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);

    ll n,m,x;

    memset(A,0,sizeof(A));

    memset(C,0,sizeof(C));

    cin>>n>>m>>x;

    for(int i=0; i<n; i++)

    {

        cin>>C[i];

        for(int j=0; j<m; j++)

        {

            cin>>A[i][j];

        }

    }

    ll Ans=10000007;

    for(int i=0; i<=4095; i++)

    {

        string s = bitset<12>(i).to_string();

        reverse(s.begin(),s.end());

        ll Cost=0,ul[14];

        memset(ul,0,sizeof(ul));

        for(int j=0; j<n; j++)

        {

            if(s[j]=='0')

                continue;

            Cost+=C[j];

            for(int k=0; k<m; k++)

            {

                ul[k]+=A[j][k];

            }

        }

        bool flag=true;

        for(int j=0; j<m; j++)

        {

            if(ul[j]<x)

                flag=false;

        }

        if(flag==true)

            Ans=min(Ans,Cost);

    }

    if(Ans==10000007)

        cout<<-1<<endl;

    else

        cout<<Ans<<endl;





    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.530214259210958x):
#include<stdio.h>

#include<iostream>

#include<algorithm>

#include<stdlib.h>

#define ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define debug freopen("in.txt","r",stdin); freopen("out.txt","w",stdout)

using namespace std;

const int MAXN=20;

typedef long long ll;

int a[MAXN][MAXN],vis[MAXN],ans[MAXN],mon[MAXN];

int n,m,x,sum=0,price=1e9;

void dfs(int pos){

	if(pos==n+1){

		for(int i=1;i<=m;i++) if(ans[i]<x) return;

		price=min(price,sum); 

		return;

	}

	dfs(pos+1);

	for(int j=1;j<=m;j++) ans[j]+=a[pos][j];

	sum+=mon[pos];

	dfs(pos+1);

	for(int i=1;i<=m;i++) ans[i]-=a[pos][i];

	sum-=mon[pos];

}

int main()

{

	ios;

	cin>>n>>m>>x;

	for(int i=1;i<=n;i++){

		cin>>mon[i];

		for(int j=1;j<=m;j++){

			cin>>a[i][j];

		}

	}

	dfs(1);

	if(price==1e9) cout<<-1<<'\n';

	else cout<<price<<'\n';

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;

ll A[14][14],C[14];

int main()

{

    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);

    ll n,m,x;

    memset(A,0,sizeof(A));

    memset(C,0,sizeof(C));

    cin>>n>>m>>x;

    for(int i=0; i<n; i++)

    {

        cin>>C[i];

        for(int j=0; j<m; j++)

        {

            cin>>A[i][j];

        }

    }

    ll Ans=10000007;

    for(int i=0; i<=4095; i++)

    {

        string s = bitset<12>(i).to_string();

        reverse(s.begin(),s.end());

        ll Cost=0,ul[14];

        memset(ul,0,sizeof(ul));

        for(int j=0; j<n; j++)

        {

            if(s[j]=='0')

                continue;

            Cost+=C[j];

            for(int k=0; k<m; k++)

            {

                ul[k]+=A[j][k];

            }

        }

        bool flag=true;

        for(int j=0; j<m; j++)

        {

            if(ul[j]<x)

                flag=false;

        }

        if(flag==true)

            Ans=min(Ans,Cost);

    }

    if(Ans==10000007)

        cout<<-1<<endl;

    else

        cout<<Ans<<endl;





    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.5317223011154193x):
#include <iostream>

#include <cstdio>

#include <cmath>

#include <string>

#include <sstream>

#include <cstring>

#include <cctype>

#include <set>

#include <queue>

#include <algorithm>



typedef long long ll;



using namespace std;

const int INF = 0x3f3f3f3f;

const int MAXN = 15;

const int MOD = 10000;



struct BOOK{

    int price;

    int a[MAXN];

}book[MAXN];

int b[MAXN];



int main()

{

    int n, m, x, price, level, ans = INF, res = 0;

    bool flag;

    scanf("%d %d %d", &n, &m, &x);



    for (int i = 0; i < n; i ++ ) {

        scanf("%d", &book[i].price);

        for (int j = 0; j < m; j ++ ) {

            scanf("%d", &book[i].a[j]);

        }

    }



    for (int i = 1; i < (1 << n); i ++ ) {

        res = 0;//统计每种情况所有书的总价格

        memset(b, 0, sizeof(b));

        for (int j = 0; j < n; j ++ ) {

            if ( i >> j & 1 ) {

                res += book[j].price;

                for (int k = 0; k < m; k ++ ) {

                    b[k] += book[j].a[k];

                }

            }

        }

        flag = true;

        for (int k = 0; k < m; k ++ ) {

            if ( b[k] < x ) {

                flag = false;

                break;

            }

        }



        if ( flag ) ans = min(ans, res);

    } 



    printf("%d", ans == INF?-1:ans);

    return 0;

}