Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <string>

using namespace std;
using namespace std::chrono;

// c++ templte for
// help...........................................................

// #define deb(x) cout<<#x<<" "<<x<<endl;/* for debuging  printing variable with
// name*/ #define debb(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl; #define
// debbb(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;

typedef long long ll;
typedef unsigned long long ull;

// for loop
// #define fo(i,n) for(int i=0;i<(ll)n;i++)
// #define Fo(i,k,n) for(int i=k;i<n;i++)

// to print vector element
// template<typename T>
// void printV(T vec){
// fo(i,vec.size()) cout<<vec[i]<<" "<<flush;
// cout<<endl;
// }

// #define modulo 1000000007
// const int INF=1e9+5;

// iterate map
// template<typename T>
// void itR(T map){
// for(auto itr=map.begin();itr!=map.end();itr++){
// debb(itr->first,itr->second)
//}
// cout<<endl;
//}

// c++ template for help........................................................

int main() {
  // stringstream ss;
  // ss<<"akhil";
  // cout<<ss.str()<<endl;
  cout << setprecision(50);
  ios::sync_with_stdio(0);
  cin.tie(0);

  // TESTCASE KO DEKH KA BHAUT SARA CONDITION GENERATE MAT KRO
  // PAPER PD CONFIRM HO JAO THORA JADA TIME HI KYU NA LGA
  // greedy ma jadatr exceptional case check kr ke dekh lo

  // WHILE DOING THE QUESTION OF DYNAMIC PROGRAMMING GREEDY KA TRAH SOCHNA BAND
  // KRO DP M DATA KA BHI USE KRNA PDTA HA BE BHULO MT DP BHI WO LEETCODE WALE
  // MATRIX KA QUESTION KI TARAH HA CONSTRAIN WILL BE THE DIMENSION OF DP DP MA
  // STATE PTA KRO AUR PHIR FUNCTION GENERATE KRO OBJECT KO CHOOSE KIA YA NAE
  // KIA AGAR KIA TO KYA HOGA AUR NAE KIA TO KYA HOGA KYA KYA CHEJ IMPORTANT HA
  // WO STATE BN JYAGA AUR HUM LOG STATE KO CHANGE KR SKTA HA JYSA KNPSACK 2
  // WALE PROBLEM MA KIA THA

  // ll testCase;
  // cin>>testCase;
  // for(ll tt=0;tt<testCase;tt++){
  ll n, m, x;
  ll mincost = 1e9 + 5;
  cin >> n >> m >> x;

  vector<vector<ll>> vec(n, vector<ll>(m + 1));
  for (ll i = 0; i < n; i++) {
    for (ll j = 0; j < m + 1; j++) {
      cin >> vec[i][j];
    }
  }

  for (ll mask = 0; mask < (1 << n); mask++) {
    ll cost = 0;
    vector<ll> v(m, 0);
    for (ll i = 0; i < n; i++) {
      if (mask & (1 << i)) {
        cost += vec[i][0];
        for (ll j = 0; j < m; j++) {
          v[j] += vec[i][j + 1];
        }
      }
    }
    ll k = 0;
    while (v[k] >= x and k < (ll)v.size()) {
      k++;
    }
    if (k == v.size())
      mincost = min(mincost, cost);
  }

  if (mincost != 1e9 + 5)
    cout << mincost << endl;
  else
    cout << -1 << endl;

  //}

  return 0;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
#include <string>

using namespace std;
using namespace std::chrono;

// c++ templte for
// help...........................................................

// #define deb(x) cout<<#x<<" "<<x<<endl;/* for debuging  printing variable with
// name*/ #define debb(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl; #define
// debbb(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;

typedef long long ll;
typedef unsigned long long ull;

// for loop
// #define fo(i,n) for(int i=0;i<(ll)n;i++)
// #define Fo(i,k,n) for(int i=k;i<n;i++)

// to print vector element
// template<typename T>
// void printV(T vec){
// fo(i,vec.size()) cout<<vec[i]<<" "<<flush;
// cout<<endl;
// }

// #define modulo 1000000007
// const int INF=1e9+5;

// iterate map
// template<typename T>
// void itR(T map){
// for(auto itr=map.begin();itr!=map.end();itr++){
// debb(itr->first,itr->second)
//}
// cout<<endl;
//}

// c++ template for help........................................................

int main() {
  // stringstream ss;
  // ss<<"akhil";
  // cout<<ss.str()<<endl;
  cout << setprecision(50);
  ios::sync_with_stdio(0);
  cin.tie(0);

  // TESTCASE KO DEKH KA BHAUT SARA CONDITION GENERATE MAT KRO
  // PAPER PD CONFIRM HO JAO THORA JADA TIME HI KYU NA LGA
  // greedy ma jadatr exceptional case check kr ke dekh lo

  // WHILE DOING THE QUESTION OF DYNAMIC PROGRAMMING GREEDY KA TRAH SOCHNA BAND
  // KRO DP M DATA KA BHI USE KRNA PDTA HA BE BHULO MT DP BHI WO LEETCODE WALE
  // MATRIX KA QUESTION KI TARAH HA CONSTRAIN WILL BE THE DIMENSION OF DP DP MA
  // STATE PTA KRO AUR PHIR FUNCTION GENERATE KRO OBJECT KO CHOOSE KIA YA NAE
  // KIA AGAR KIA TO KYA HOGA AUR NAE KIA TO KYA HOGA KYA KYA CHEJ IMPORTANT HA
  // WO STATE BN JYAGA AUR HUM LOG STATE KO CHANGE KR SKTA HA JYSA KNPSACK 2
  // WALE PROBLEM MA KIA THA

  // ll testCase;
  // cin>>testCase;
  // for(ll tt=0;tt<testCase;tt++){
  ll n, m, x;
  ll mincost = 1e9 + 5;
  cin >> n >> m >> x;

  vector<vector<ll>> vec(n, vector<ll>(n));
  for (ll i = 0; i < n; i++) {
    for (ll j = 0; j < m + 1; j++) {
      cin >> vec[i][j];
    }
  }

  for (ll mask = 0; mask < (1 << n); mask++) {
    ll cost = 0;
    vector<ll> v(m, 0);
    for (ll i = 0; i < n; i++) {
      if (mask & (1 << i)) {
        cost += vec[i][0];
        for (ll j = 0; j < m; j++) {
          v[j] += vec[i][j + 1];
        }
      }
    }
    ll k = 0;
    while (v[k] >= x and k < v.size()) {
      k++;
    }
    if (k == v.size())
      mincost = min(mincost, cost);
  }

  if (mincost != INT_MAX)
    cout << mincost << endl;
  else
    cout << -1 << endl;

  //}

  return 0;
}