#include "bits/stdc++.h" #define in std::cin #define out std::cout #define rep(i,N) for(LL i=0;i> N >> M >> K; std::vector>A(N, std::vector(M)); rep(i, N) rep(j, M) in >> A[i][j]; LL min = 0; rep(i, N) min += A[i][0]; if (min > K) { out << -1 << std::endl; return 0; } std::vectorv1, v2; v1.push_back(0); v2.push_back(0); rep(i, N / 2) { std::vectornewV1; rep(j, v1.size()) rep(k, M) newV1.push_back(v1[j] + A[i][k]); v1 = newV1; } for (LL i = N / 2; i < N; ++i) { std::vectornewV2; rep(j, v2.size()) rep(k, M) newV2.push_back(v2[j] + A[i][k]); v2 = newV2; } std::sort(v1.begin(), v1.end()); std::sort(v2.begin(), v2.end()); LL ans = 0; rep(i, v1.size()) { if (v1[i] > K) continue; auto it = std::upper_bound(v2.begin(), v2.end(), K - v1[i]); if (it != v2.begin()) ans = std::max(ans, v1[i] + *(it - 1)); } out << K - ans << std::endl; }