#pragma region #pragma GCC target("avx2") #pragma GCC optimize("03") #pragma GCC optimize("unroll-loops") #include using namespace std; typedef long double ld; typedef long long ll; typedef unsigned long long ull; #define endl "\n" #define FOR(i,a,b) for(int i=(a);i<=(b);i++) #define PII pair #define PLL pair #define VPII vector #define VPLL vector #define ALL(x) (x).begin(), (x).end() constexpr int INF=1<<30; constexpr ll LINF=1LL<<60; constexpr ll mod=1e9+7; constexpr int NIL = -1; templateinline bool chmax(T &a, const T &b) { if (ainline bool chmin(T &a, const T &b) { if (b v1; vector v2; void dfs(int i, int ed, int cur, vector& v) { if(i==ed) { for(int j=0; j> n >> m >> k; FOR(i,0,n-1) { FOR(j,0,m-1) { cin >> a[i][j]; } } int mid = n/2; if(n > 1) { dfs(0, mid-1, 0, v1); dfs(mid, n-1, 0, v2); int ans = INF; for(auto &e: v1){ int now = k - e; if(now <= 0) continue; auto resi = upper_bound(ALL(v2), now); if(resi != v2.begin()) chmin(ans, now - *(resi-1)); } if(ans != INF) cout << ans << endl; else cout << -1 << endl; } else { FOR(i,0,m-1) v1.push_back(a[0][i]); auto resi = upper_bound(ALL(v1), k); if(resi != v1.begin()) cout << k - *(resi-1) << endl; else cout << -1 << endl; } return 0; }