alexjercan/bugnet huggingface dataset:
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"

using namespace std;

const long long inf = 1e9;
#define ll long long
#define fr(i, a, n) for (int i = a; i < n; i++)
#define rfr(i, n, a) for (int i = n; i >= a; i--)
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define endl "\\n"
typedef vector<int> VI;
typedef vector<ll> VL;
typedef priority_queue<int> Pqi;
typedef priority_queue<ll> Pql;

ll n, m, k;
ll arr[14][14];
ll dp[500000];
ll solv(ll mask) {
  if (dp[mask] != -1)
    return dp[mask];
  VL v(m + 2);
  ll ret = 0;
  fr(i, 0, n) {
    if (mask & (1 << i)) {
      ret += arr[i][0];
      fr(j, 1, m + 1) { v[j] += arr[i][j]; }
    }
  }
  bool can = 0;
  fr(i, 1, m + 1) {
    if (v[i] < k) {
      ret = 1e18;
      break;
    }
  }
  fr(i, 0, n) {
    if (mask & (1LL << i))
      continue;
    ret = min(ret, solv(mask | (1 << i)));
  }
  return dp[mask] = ret;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> k;
  memset(dp, -1, sizeof dp);
  ll mask = (1 << 18);
  fr(i, 0, n) {
    fr(j, 0, m + 1) { cin >> arr[i][j]; }
  }
  ll ans = solv(mask);
  cout << (ans == 1e18 ? -1 : ans) << endl;
  return 0;
}

Error: 0

Fixed submission:

#include "bits/stdc++.h"

using namespace std;

const long long inf = 1e9;
#define ll long long
#define fr(i, a, n) for (int i = a; i < n; i++)
#define rfr(i, n, a) for (int i = n; i >= a; i--)
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define endl "\\n"
typedef vector<int> VI;
typedef vector<ll> VL;
typedef priority_queue<int> Pqi;
typedef priority_queue<ll> Pql;

ll n, m, k;
ll arr[14][14];
ll mi = 9e18;
bool dp[33000];
bool solv(ll mask) {
  if (dp[mask])
    return 0;
  dp[mask] = 1;
  bool ret = 0;
  for (int i = 0; i < n; i++) {
    if (mask & (1LL << i))
      continue;
    ret |= solv(mask ^ (1LL << i));
  }
  ll ck = 0;
  VL lev(m + 1);
  for (int i = 0; i < n; i++) {
    if (mask & (1LL << i)) {
      ck += arr[i][0];
      for (int j = 1; j <= m; j++) {
        lev[j] += arr[i][j];
      }
    }
  }
  fr(i, 1, m + 1) {
    if (lev[i] < k) {
      return ret;
    }
  }
  mi = min(mi, ck);
  return 1;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> k;
  memset(dp, 0, sizeof dp);
  ll mask = (1LL << 15);
  fr(i, 0, n) {
    fr(j, 0, m + 1) { cin >> arr[i][j]; }
  }
  if (solv(mask)) {
    cout << mi << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;

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

  int ans = 1e9;
  for (int i = 0; i < (1 << n); i++) {
    int sum = 0;
    bool flag = true;
    vector<int> v(n, 0);
    for (int j = 0; j < n; j++) {
      if (i & (1 << j)) {
        sum += c[j];
        for (int k = 0; k < m; k++) {
          v[k] += a[j][k];
        }
      }
    }
    for (int l = 0; l < m; l++) {
      if (v[l] < x)
        flag = false;
    }
    if (flag)
      ans = min(ans, sum);
  }
  if (ans == 1e9)
    cout << -1 << endl;
  else
    cout << ans << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;

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

  int ans = 1e9;
  for (int i = 0; i < (1 << n); i++) {
    int sum = 0;
    bool flag = true;
    vector<int> v(n, 0);
    for (int j = 0; j < n; j++) {
      if (i & (1 << j)) {
        sum += c[j];
        for (int k = 0; k < m; k++) {
          v[k] += a[j][k];
        }
      }
    }
    for (int l = 0; l < m; l++) {
      if (v[l] < x)
        flag = false;
    }
    if (flag)
      ans = min(ans, sum);
  }
  if (ans == 1e9)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define endl "\\n"
#define ll long long int
#define mod 1000000007

using namespace std;
int arr[20];
struct algo {
  int cst;
  int al[20];
};

ll getval(vector<algo> v, int n, int m, int x) {
  bool ans = true;
  for (int i = 0; i < m; i++) {
    if (arr[i] < x) {
      ans = false;
      break;
    }
  }
  if (ans)
    return 0;
  if (n == 0) {
    return INT_MAX;
  }
  ll ans1 = getval(v, n - 1, m, x);
  for (int i = 0; i < m; i++) {
    arr[i] += v[n - 1].al[i];
  }
  ll ans2 = v[n - 1].cst + getval(v, n - 1, m, x);
  for (int i = 0; i < m; i++) {
    arr[i] -= v[n - 1].al[i];
  }
  return min(ans1, ans2);
}

int solve() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<algo> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i].cst;
    for (int j = 0; j < m; j++) {
      cin >> v[i].al[j];
      arr[i] = 0;
    }
  }

  ll answ = getval(v, n, m, x);
  if (answ == INT_MAX)
    return -1;
  return answ;
}
int main() {
  // #ifndef ONLINE_JUDGE
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  // #endif
  std::ios::sync_with_stdio(false);
  cout << solve();
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define endl "\\n"
#define ll long long int
#define mod 1000000007

using namespace std;
struct algo {
  int cst;
  int al[20];
};

ll getval(vector<algo> v, int n, int m, int x, ll arr[]) {
  bool ans = true;
  for (int i = 0; i < m; i++) {
    if (arr[i] < x) {
      ans = false;
      break;
    }
  }
  if (ans)
    return 0;
  if (n == 0) {
    return 100001;
  }
  ll ans1 = getval(v, n - 1, m, x, arr);
  for (int i = 0; i < m; i++) {
    arr[i] += v[n - 1].al[i];
  }
  ll ans2 = v[n - 1].cst + getval(v, n - 1, m, x, arr);
  for (int i = 0; i < m; i++) {
    arr[i] -= v[n - 1].al[i];
  }
  return min(ans1, ans2);
}

int solve() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<algo> v(n);
  ll arr[m];
  for (int i = 0; i < n; i++) {
    cin >> v[i].cst;
    for (int j = 0; j < m; j++) {
      cin >> v[i].al[j];
      arr[i] = 0;
    }
  }

  ll answ = getval(v, n, m, x, arr);
  if (answ == 100001)
    return -1;
  return answ;
}
int main() {
  // #ifndef ONLINE_JUDGE
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  // #endif
  std::ios::sync_with_stdio(false);
  cout << solve();
  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int N, M, X;
vector<int> C;
vector<vector<int>> A;
const int INF = 1e+9;

void dfs(vector<int> &bit, int &res) {

  if (bit.size() == N) {
    int cost = 0;
    vector<int> skill(M);
    // 本を買ったらコストと理解度を加算する
    for (int i = 0; i < N; i++) {
      if (bit[i]) {
        cost += C[i];
        for (int j = 0; j < M; j++) {
          skill[j] += A[i][j];
        }
      }
    }
    bool ok = true;
    for (int i = 0; i < M; i++) {
      if (skill[i] < X) {
        ok = false;
        break;
      }
    }
    if (ok)
      res = min(res, cost);

    return;
  }

  for (int i = 0; i < 2; i++) {
    bit.push_back(i);
    dfs(bit, res);
    bit.pop_back();
  }
  return;
}

int main(void) {
  // 入力
  cin >> N >> M >> X;
  C.resize(N);
  A.resize(N, vector<int>(M));

  for (int i = 0; i < N; i++) {
    cin >> C[i];
    for (int j = 0; j < M; j++) {
      cin >> A[i][j];
    }
  }

  int res = INF;
  vector<int> bit;
  dfs(bit, res);

  if (res == INF)
    cout << -1 << endl;
  else
    cout << res << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int N, M, X;
vector<int> C;
vector<vector<int>> A;
const int INF = 1e+9;

void dfs(vector<int> &bit, int &res) {

  if (bit.size() == N) {
    int cost = 0;
    vector<int> skill(N);
    // 本を買ったらコストと理解度を加算する
    for (int i = 0; i < N; i++) {
      if (bit[i]) {
        cost += C[i];
        for (int j = 0; j < M; j++) {
          skill[j] += A[i][j];
        }
      }
    }
    bool ok = true;
    for (int i = 0; i < M; i++) {
      if (skill[i] < X) {
        ok = false;
        break;
      }
    }
    if (ok)
      res = min(res, cost);

    return;
  }

  for (int i = 0; i < 2; i++) {
    bit.push_back(i);
    dfs(bit, res);
    bit.pop_back();
  }
}

int main(void) {
  // 入力
  cin >> N >> M >> X;
  C.resize(N);
  A.resize(N, vector<int>(M));

  for (int i = 0; i < N; i++) {
    cin >> C[i];
    for (int j = 0; j < M; j++) {
      cin >> A[i][j];
    }
  }

  int res = INF;
  vector<int> bit;
  dfs(bit, res);

  if (res == INF)
    cout << -1 << endl;
  else
    cout << res << endl;

  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

const int INF = 1e+10;

int main(void) {
  // 入力
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> C(N);
  vector<vector<int>> A(N, vector<int>(M));

  for (int i = 0; i < N; i++) {
    cin >> C[i];
    for (int j = 0; j < M; j++) {
      cin >> A[i][j];
    }
  }

  int ans = INF;
  for (int bit = 0; bit < (1 << N); bit++) {
    int cost = 0;
    vector<int> D(M);
    for (int i = 0; i < N; i++) {
      if (bit >> i & 1) {
        cost += C[i];
        for (int j = 0; j < M; j++) {
          D[j] += A[i][j];
        }
      }
    }
    bool ok = true;
    for (int i = 0; i < M; i++) {
      if (D[i] < X) {
        ok = false;
        break;
      }
    }
    if (ok)
      ans = min(ans, cost);
  }
  if (ans == INF)
    cout << -1 << endl;
  else
    cout << ans << endl;

  return 0;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main(void) {
  // 入力
  long long N, M, X;
  cin >> N >> M >> X;
  vector<long long> C(N);
  vector<vector<long long>> A(N, vector<long long>(M));

  for (int i = 0; i < N; i++) {
    cin >> C[i];
    for (int j = 0; j < M; j++) {
      cin >> A[i][j];
    }
  }

  int ans = 1e+9;
  for (int i = 0; i < (1 << N); i++) {
    int cost = 0;
    vector<int> D(M);
    for (int j = 0; j < N; j++) {
      if (i >> j & 1) {
        cost += C[j];
        for (int k = 0; k < M; k++) {
          D[j] += A[i][j];
        }
      }
    }
    bool ok = true;
    for (int j = 0; j < M; j++) {
      if (D[j] < X) {
        ok = false;
      }
    }
    if (ok)
      ans = min(ans, cost);
  }
  if (ans == 1e+9)
    cout << -1 << endl;
  else
    cout << ans << endl;

  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

const int INF = 1001001001;

int a[12][12];

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);

  for (int i = 0; i < n; ++i) {
    cin >> c[i];
    for (int j = 0; j < m; ++j)
      cin >> a[i][j];
  }
  // 3 3 10
  //  c{60,70,50} 縦i 横j
  // 60 2 2 4
  // 70 8 7 9
  // 50 2 3 9
  int ans = INF;
  for (int s = 0; s < (1 << n); ++s) // sが0~7
  {
    int cost = 0;
    vector<int> d(m);
    for (int i = 0; i < n; ++i) {
      if (s >> i & 1) // i=0 001 011 101 111のときにtrueを返す
      // i=1 010 011 110 111　の時true
      // i=2 100 101 110 111
      {
        cost += c[i];
        for (int j = 0; j < m; ++j)
          d[j] += a[i][j];
      }
    }
    // s=3の時、cost=c[0]+c[1]=130 d[0]=a[0][0]+a[1][0]=10
    // d[1]=a[0][1]+a[1][1]=9 d[2]=a[0][2]+a[1][2]=13
    bool ok = true;
    for (int j = 0; j < m; ++j)
      if (d[j] < x)
        ok = false; // false
    if (ok)
      ans = min(ans,
                cost); // すべてx以上という条件を満たしたらansの値をcostで更新
  }
  if (ans == INF)
    cout << -1 << endl; // 1回も更新されなかった場合
  else
    cout << ans << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int N, M, X;
vector<int> C;
vector<vector<int>> A;

int main() {
  cin >> N >> M >> X;
  int i;
  int j;
  C.resize(N);
  A.resize(N, vector<int>());

  for (i = 1; i <= N; i++) {
    cin >> C[i];
    A[i].resize(M);
    for (j = 1; j <= M; j++) {
      cin >> A[i][j];
    }
  }
  int sum = 0;
  for (j = 1; j <= M; j++) {
    for (i = 1; i <= N; i++) {
      sum += A[i][j];
    }
    if (sum < X) {
      cout << "-1" << endl;
      break;
    }
  }
}
Problem p02683 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(x) x.begin(), x.end()
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

ll n, m, x;
vector<ll> c, res;
vector<vector<ll>> a;
ll ans = 1001002003004005006ll;
vector<bool> u;
void solve(ll price, int pos) {
  int is = 0;
  rep(i, m) {
    if (res[i] < x)
      is = 1;
  }
  if (!is) {
    chmin(ans, price);
    return;
  }
  if (pos >= n)
    return;
  for (int i = pos; i < n; i++) {
    if (u[i])
      continue;
    u[i] = 1;
    rep(j, m) { res[j] += a[i][j]; }
    solve(price + c[i], i + 1);
    rep(j, m) { res[j] -= a[i][j]; }
    u[i] = 0;
  }

  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  cin >> n >> m >> x;
  c.resize(n);
  a.resize(n);
  u.resize(n);
  res.resize(n);
  rep(i, n) {
    cin >> c[i];

    rep(j, m) {
      ll aij;
      cin >> aij;
      a[i].push_back(aij);
    }
  }
  solve(0ll, 0);
  if (ans != 1001002003004005006ll)
    cout << ans << endl;
  else
    cout << -1 << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(x) x.begin(), x.end()
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

ll n, m, x;
vector<ll> c, res;
vector<vector<ll>> a;
ll ans = 1001002003004005006ll;
vector<bool> u;
void solve(ll price) {
  int is = 0;
  rep(i, m) {
    if (res[i] < x)
      is = 1;
  }
  if (!is) {
    chmin(ans, price);
    return;
  }
  rep(i, n) {
    if (u[i])
      continue;
    u[i] = 1;
    rep(j, m) { res[j] += a[i][j]; }
    solve(price + c[i]);
    rep(j, m) { res[j] -= a[i][j]; }
    u[i] = 0;
  }

  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  cin >> n >> m >> x;
  c.resize(n);
  a.resize(n);
  u.resize(n);
  res.resize(n);
  rep(i, n) {
    cin >> c[i];

    rep(j, m) {
      ll aij;
      cin >> aij;
      a[i].push_back(aij);
    }
  }
  solve(0ll);
  if (ans != 1001002003004005006ll)
    cout << ans << endl;
  else
    cout << -1 << endl;
  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int, int>;
#define rep(i, n)                                                              \\
  for (int i = 0; i < (int)(n); i++) // 範囲外参照とループの初期化に注意！

const int INF = 100100100;
int main() {
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> cost(N);
  vector<vector<int>> A(N, vector<int>(M));
  rep(i, N) {
    cin >> cost[i];
    rep(j, M) { cin >> A[i][j]; }
  }
  int ans = INF;
  rep(is, 1 << N) {
    bool can = true;
    int sum = 0;
    vector<int> und(M, 0);
    rep(i, N) {
      if (is >> i & 1) {
        sum += cost[i];
        rep(j, M) { und[j] += A[i][j]; }
      }
    }
    rep(i, M) {
      if (und[i] < X)
        can = false;
    }
    if (can) {
      ans = min(ans, sum);
    }
  }
  if (ans == INF)
    ans = -1;
  cout << ans << endl;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60; // intじゃ扱えないことに注意！
#define mod 1000000007
#define rep(i, n)                                                              \\
  for (int i = 0; i < (int)(n); i++) // 範囲外参照とループの初期化に注意！

ll N, M, X;
ll money = 0;
ll ans = INF;
vector<ll> cost(N);
vector<bool> seen(N, false);
vector<bool> ok(M, false);
vector<ll> underst(M, 0);
ll A[12][12];

void dfs(int n) {
  bool owari = true;
  seen[n] = true;
  money += cost[n];
  for (int j = 0; j < M; j++) {
    underst[j] += A[n][j];
    if (underst[j] >= X) {
      ok[j] = true;
    }
  }
  for (int j = 0; j < M; j++) {
    if (ok[j] == false) {
      owari = false;
      break;
    }
    if (owari == true) {
      ans = min(ans, money);
      money = 0;
      return;
    }
  }
  if (owari == false) {
    for (int i = 0; i < N; i++) {
      if (seen[i] == true) {
        continue;
      }
      dfs(i);
    }
  }
}

int main() {
  cin >> N >> M >> X;
  for (int i = 0; i < N; i++) {
    cin >> cost[i];
    for (int j = 0; j < M; j++) {
      cin >> A[i][j];
    }
  }

  for (int i = 0; i < N; i++) {
    dfs(i);
  }

  cout << ans << endl;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  std::vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m));
  for (int i = 0; i < n; i++) {
    cin >> c.at(i);
    for (int j = 0; j < m; j++) {
      cin >> a.at(i).at(j);
    }
  }
  int min1 = 1000000000;
  rep(tmp, 1 << n) {
    bitset<12> s(tmp);
    int cost = 0;
    bool ans = true;
    std::vector<int> d(m);
    rep(i, m) d.at(i) = 0;
    rep(i, n) {
      if (s.test(i)) {
        rep(j, m) { d.at(j) += a.at(i).at(j); }
        cost += c.at(i);
      }
    }
    for (int i = 0; i < m; i++) {
      if (d.at(i) < x)
        ans = false;
    }
    if (ans)
      min1 = min(min1, cost);
  }

  if (min1 == 1000000000)
    std::cout << "-1" << '\\n';
  else
    std::cout << min1 << '\\n';
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  std::vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m));
  for (int i = 0; i < n; i++) {
    cin >> c.at(i);
    for (int j = 0; j < m; j++) {
      cin >> a.at(i).at(j);
    }
  }
  int cost = 0;
  bool ans = true;
  std::vector<int> d(n);
  rep(i, n) d.at(i) = 0;
  int min1 = 1000000000;
  rep(tmp, 1 << n) {
    bitset<12> s(tmp);
    int cost = 0;
    bool ans = true;
    std::vector<int> d(n);
    rep(i, n) d.at(i) = 0;
    rep(i, n) {
      if (s.test(i)) {
        rep(j, n) { d.at(j) += a.at(i).at(j); }
        cost += c.at(i);
      }
    }
    for (int i = 0; i < n; i++) {
      if (d.at(i) < x)
        ans = false;
    }
    if (ans)
      min1 = min(min1, cost);
  }

  if (min1 == 1000000000)
    std::cout << "-1" << '\\n';
  else
    std::cout << min1 << '\\n';
  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
using ll = long long int;
using P = pair<int, int>;

#define loop(i, n) for (int i = 0; i < n; i++)
#define INF 1000000000

int n, m, x;

int ans = INF;

void dfs(int i, vector<int> c, vector<vector<int>> a, int total,
         vector<int> check) {
  bool ok = true;
  loop(j, m) {
    if (check[j] < x)
      ok = false;
  }
  if (ok)
    ans = min(ans, total);

  if (i == n)
    return;

  dfs(i + 1, c, a, total, check);

  loop(j, m) { check[j] += a[i][j]; }
  total += c[i];
  dfs(i + 1, c, a, total, check);
}

int main(void) {

  cin >> n >> m >> x;

  vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m));
  vector<int> check(m);
  loop(i, n) {
    cin >> c[i];
    loop(j, m) { cin >> a[i][j]; }
  }

  dfs(0, c, a, 0, check);

  if (ans == INF) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long int;
using P = pair<int, int>;

#define loop(i, n) for (int i = 0; i < n; i++)
#define INF 1000000000

int main(void) {

  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m));
  vector<int> check(n, 0);
  loop(i, n) {
    cin >> c[i];
    loop(j, m) cin >> a[i][j];
  }

  ll ans = INF;

  loop(bit, 1 << n) {
    ll temp = 0;
    loop(i, n) {
      if (bit & 1 << i) {
        temp += c[i];
        loop(j, m) check[j] += a[i][j];
      }
    }
    bool ok = true;
    loop(i, m) if (check[i] < x) ok = false;
    if (ok)
      ans = min(ans, temp);
    loop(i, m) check[i] = 0;
  }

  cout << (ans == INF ? -1 : ans) << endl;

  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {

  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  int a[12][12];
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }

  int cost;
  int ans = INF;
  for (int s = 0; s < (1 << n); s++) {
    cost = 0;
    vector<int> v(m);
    bool flg = true;
    for (int i = 0; i < n; i++) {
      if ((s >> i) & 1) {
        cost += c[i];
        for (int j = 0; j < m; j++) {
          v[j] += a[i][j];
        }
      }
    }
    for (int j = 0; j < m; j++) {
      if (v[j] < x)
        flg = false;
    }
    if (flg)
      ans = min(ans, cost);
  }
  if (ans == INF)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int cost;
int cost_min;
bool check(vector<int> V, int n, int x) {
  bool flg = true;
  for (int i = 0; i < n; i++) {
    if (x > V[i])
      flg = false;
  }
  return flg;
}
vector<bool> seen;
void dfs(vector<int> C, vector<vector<int>> A, vector<int> V, int N, int M,
         int X) {
  if (check(V, M, X)) {
    if (cost_min > cost)
      cost_min = cost;
  }
  for (int i = 0; i < N; i++) {
    if (seen[i])
      continue;
    seen[i] = true;
    cost += C[i];
    for (int j = 0; j < M; j++) {
      V[j] += A[i][j];
    }
    dfs(C, A, V, N, M, X);
    seen[i] = false;
    cost -= C[i];
    for (int j = 0; j < M; j++) {
      V[j] -= A[i][j];
    }
  }
}
int main() {

  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m));
  vector<int> v(m);
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    for (int j = 0; j < m; j++) {
      int t;
      cin >> t;
      a[i][j] = t;
    }
  }
  seen.assign(n, false);
  cost = 0;
  cost_min = INF;
  dfs(c, a, v, n, m, x);
  if (cost_min == INF)
    cout << -1 << endl;
  else
    cout << cost_min << endl;

  return 0;
}