Advertisement
Ahmed_Negm

G

Apr 14th, 2024
993
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5. #define nl "\n"
  6.  
  7. void files(){
  8.     ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
  9.     #ifndef ONLINE_JUDGE
  10.         freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  11.     #endif
  12. }
  13.  
  14.  
  15. void solve(){
  16.     ll n,m,x; cin>>n>>m>>x;
  17.  
  18.     vector<vector<ll>> a(n, vector<ll>(m+1));
  19.     for(ll i=0; i<n; i++){
  20.         for(ll j=0; j<=m; j++){
  21.             cin>>a[i][j];
  22.         }
  23.     }
  24.  
  25.  
  26.  
  27.     ll ans = LONG_LONG_MAX;
  28.  
  29.     for(int i=0; i<(1<<n); i++){
  30.         ll sum = 0;
  31.         vector<ll> b(m);
  32.         for(int j=0; j<n; j++){
  33.             if(i&(1<<j)){
  34.                 sum += a[j][0];
  35.                for(int k=1;k<=m;k++){
  36.                 b[k-1] += a[j][k];
  37.                }
  38.             }
  39.         }
  40.  
  41.         sort(b.begin(), b.end());
  42.         if(b[0]>=x){
  43.             ans = min(ans, sum);
  44.         }
  45.     }
  46.  
  47.     if(ans == LONG_LONG_MAX){
  48.         cout<<-1<<nl;
  49.     }else cout<<ans<<nl;
  50.  
  51. }
  52.  
  53. int main(){
  54.     files();
  55.     int t = 1;
  56.     // cin>>t;
  57.     while(t--) solve();
  58.  
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement