#include using namespace std; int main() { //入力 clock_t start = clock(); int N,M,K; cin >> N >> M >> K; vector> a(N,vector(M)); for(int i = 0; i < N; ++i) { for(int j = 0; j < M; ++j) { cin >> a[i][j]; } } random_device rnd; // 非決定的な乱数生成器を生成 mt19937 mt(rnd()); // メルセンヌ・ツイスタの32ビット版、引数は初期シード値 uniform_int_distribution<> randN(1, M); // [0, 99] 範囲の一様乱数 int ans = K; while(1) { int sum = 0; for(int i = 0; i < N; ++i) { sum += a[i][randN(mt)-1]; } if(sum<=K && ans > K - sum) ans=K-sum; clock_t end = clock(); double time = static_cast(end - start) / CLOCKS_PER_SEC * 1000.0; if(time>1980.) break; } if(ans==K) ans = -1; cout << ans << endl; return 0; }