fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define endl '\n'
  5. ll N = 1e9+7;
  6. ll oo =1e13;
  7. const ll maxx = 1000000 + 3;
  8. ll n,m,k,q,x,y,z,l,r,mid,ans;
  9. string s1,s2;
  10. vector<vector<ll>>arr(15,vector<ll>(15,0));
  11.  
  12. ll go(ll ind ,vector<ll>v) {
  13. if (ind==n) {
  14. for (ll i=1;i<=m;i++) {
  15. if (v[i] < x)return oo;
  16. }
  17. return 0;
  18. }
  19.  
  20. vector<ll>vch1=v;
  21. for (ll i=1;i<=m;i++){vch1[i]+=arr[ind][i];}
  22.  
  23. ll ch1 = go(ind+1,vch1)+arr[ind][0];
  24. ll ch2 = go(ind+1,v);
  25.  
  26. return min(ch1,ch2);
  27. }
  28. void solve() {
  29. cin>>n>>m>>x;
  30. for (ll i =0 ;i <n;i++) {
  31. for (ll j=0;j<=m;j++) {
  32. cin>>arr[i][j];
  33. }
  34. }
  35. vector<ll>v(m+1,0);
  36. ll o = go(0,v);
  37. if (o==oo)cout<<-1;
  38. else cout <<o;
  39. }
  40. int main() {
  41. ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  42. ll t=1 ;
  43. // cin >>t;
  44. while (t--) {
  45. ans=0;
  46. solve();
  47. }
  48. }
Success #stdin #stdout 0s 5320KB
stdin
8 5 22
100 3 7 5 3 1
164 4 5 2 7 8
334 7 2 7 2 9
234 4 7 2 8 2
541 5 4 3 3 6
235 4 8 6 9 7
394 3 6 1 6 2
872 8 4 3 7 2
stdout
1067