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

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define ld long double
#define pb push_back
#define MOD 1000000007
#define inf 3e18
#define vi vector<int>
#define vld vector<ld>
#define pii pair<int, int>
#define mii map<int, int>
#define fi first
#define se second
#define fastIO                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  cerr << " " << name << " : " << arg1 << '\\n';
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}

void inp_out() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("debug.txt", "w", stderr);
#endif
}

int32_t main() {
  fastIO inp_out();
  int n, m, x;
  cin >> n >> m >> x;
  vi cost(n);
  vector<vi> a(n, vi(m));
  for (int i = 0; i < n; ++i) {
    cin >> cost[i];
    for (int j = 0; j < m; ++j) {
      cin >> a[i][j];
    }
  }

  int rg = pow(2, n);
  int ans = inf;
  for (int i = 1; i < rg; ++i) {
    int val = i;
    vi know(m);
    int t = 0, temp = 0;
    while (val > 0) {
      if (val & 1) {
        temp += cost[t];
        for (int j = 0; j < m; ++j) {
          know[j] += a[t][j];
        }
      }
      val /= 2;
      ++t;
    }

    int flag = 1;
    for (int j = 0; j < m; ++j)
      if (know[j] < x)
        flag = 0;
    if (flag)
      ans = min(ans, temp);
  }

  cout << (ans == inf ? -1 : ans);

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define ld long double
#define pb push_back
#define MOD 1000000007
#define inf 3e18
#define vi vector<int>
#define vld vector<ld>
#define pii pair<int, int>
#define mii map<int, int>
#define fi first
#define se second
#define fastIO                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  cerr << " " << name << " : " << arg1 << '\\n';
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}

void inp_out() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("debug.txt", "w", stderr);
#endif
}

int32_t main() {
  fastIO inp_out();
  int n, m, x;
  cin >> n >> m >> x;
  vi cost(n);
  vector<vi> a(n, vi(m));
  for (int i = 0; i < n; ++i) {
    cin >> cost[i];
    for (int j = 0; j < m; ++j) {
      cin >> a[i][j];
      //	db(i,j);
    }
  }

  int rg = pow(2, n);
  int ans = inf;
  for (int i = 1; i < rg; ++i) {
    int val = i;
    vi know(m);
    int t = 0, temp = 0;
    while (val > 0) {
      if (val & 1) {
        temp += cost[t];
        for (int j = 0; j < n; ++j) {
          know[j] += a[t][j];
        }
      }
      val /= 2;
      ++t;
    }

    int flag = 1;
    for (int j = 0; j < m; ++j)
      if (know[j] < x)
        flag = 0;
    if (flag)
      ans = min(ans, temp);
  }

  cout << (ans == inf ? -1 : ans);

  return 0;
}