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

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

// template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return
// true; } return false; }
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  /*Cだけrep(j,m)に入れないでcinするのが分からなくて
  n*(m+1)行列にCもAも入れようとしてた*/
  vector<vector<int>> a(n, vector<int>(m));
  rep(i, n) {
    cin >> c.at(i);                 // c[i]
    rep(j, m) cin >> a.at(i).at(j); // a[i][j]
  }

  int all = 1 << n; // 2^n 全通り
  /*わざわざ分けて定義しなくて良い*/
  // int INF = 1200001; //10^5円を12冊買った場合より高い
  // int ans = INF; //求める最小値　起こりえない金額で初期化
  int ans = 1200001;
  /*以下3つ定義＆初期化する場所気をつける*/
  // int cost = 0; //買った参考書の合計金額
  // vector<int> level(m); //j番目のアルゴリズムの理解度
  // bool ok = true; //全アルゴリズムで理解度がxより高いか判定

  rep(mask, all) { // 全通り試す。bit全探索
    vector<int> level(
        m); // 前に試した場合でのlevel引きずらないために宣言する場所に注意
    int cost = 0; // 上に同じ
    rep(i, n) {
      /*n→0の順で並んでるから右にiずらせばi番目の参考書の0/1が最下位bitにくる*/
      if (mask >> i & 1) { // i番目の参考書買ってれば //1&1だけ1
        cost += c[i];
        rep(j, m) level[j] += a[i][j];
      }
    }
    bool ok =
        true; // 上に同じ。前に試した場合でfalse入っちゃってても戻せる。使う直前で宣言すると無難かな
    rep(j, m) {
      if (level[j] < x)
        ok = false;
    }
    if (ok)
      // chmin(ans,cost);
      /*cost[i]とcost[i+1]の大小ずっと比べてくとかじゃないからchminじゃなくて良い*/
      ans = min(ans, cost);
  }
  if (ans == 1200001)
    cout << -1 << endl;
  else
    cout << ans << endl;
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 0) >= this->size() (which is 0)


Fixed submission:

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

int main() {
  int n, m, x;
  vector<vector<int>> data(n, vector<int>(m + 1));
  vector<int> sum;
  cin >> n >> m >> x;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m + 1; j++) {
      cin >> data.at(i).at(j);
    }
  }
  for (int j = 1; j < m + 1; j++) {
    for (int i = 0; i < n; i++) {
      sum.at(j - 1) += data.at(i).at(j);
    }
  }
  for (int j = 0; j < m; j++) {
    if (sum.at(j) < x) {
      cout << -1 << endl;
      break;
    }
  }
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

int N, M, X;
int C[13];
int A[13][13];
int minC;

void calc(int nowN, vector<int> nowM, int nowC) {
  if (nowN == N) {
    for (int i = 0; i < M; i++) {
      if (nowM[i] < X) {
        return;
      }
    }

    if (nowC < minC) {
      minC = nowC;
    }

    return;
  } else {
    vector<int> nextM = vector<int>(nowM);
    calc(nowN + 1, nextM, nowC);

    for (int i = 0; i < M; i++) {
      nextM[i] += A[nowN][i];
    }
    calc(nowN + 1, nextM, (nowC + C[nowN]));
  }
}

int main() {
  cin >> N >> M >> X;

  int max[13] = {0};
  int maxC = 0;

  for (int i = 0; i < N; i++) {
    cin >> C[i];
    maxC += C[i];

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

  // all max[] is over X?
  bool checkX = true;
  for (int i = 0; i < M; i++) {
    if (max[i] < X) {
      checkX = false;
      break;
    }
  }

  if (!checkX) {
    minC = -1;
  } else {
    minC = maxC;
    vector<int> tmpV;
    for (int i = 0; i < M; i++) {
      tmpV.push_back(0);
    }

    calc(0, tmpV, 0);
  }

  cout << minC << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

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

void calc(int nowN, vector<int> nowM, int nowC) {
  if (nowN == N) {
    for (int i = 0; i < M; i++) {
      if (nowM[i] < X) {
        return;
      }
    }

    if (nowC < minC) {
      minC = nowC;
    }

    return;
  } else {

    calc(nowN + 1, nowM, nowC);

    vector<int> nextM = vector<int>(nowM);
    for (int i = 0; i < M; i++) {
      nextM[i] += A[nowN][i];
    }
    calc(nowN + 1, nextM, (nowC + C[nowN]));
  }
}

int main() {
  cin >> N >> M >> X;

  vector<int> max = {0};
  int maxC = 0;

  for (int i = 0; i < N; i++) {
    int tmpC;
    cin >> tmpC;
    C.push_back(tmpC);
    maxC += tmpC;

    vector<int> tmpA;

    for (int j = 0; j < M; j++) {
      int tmpAa;
      cin >> tmpAa;
      tmpA.push_back(tmpAa);
      max[j] += tmpAa;
    }
    A[i] = tmpA;
  }

  // all max[] is over X?
  bool checkX = true;
  for (int i = 0; i < M; i++) {
    if (max[i] < X) {
      checkX = false;
      break;
    }
  }

  if (!checkX) {
    minC = -1;
  } else {
    minC = maxC;
    vector<int> tmpV;
    for (int i = 0; i < M; i++) {
      tmpV.push_back(0);
    }

    calc(0, tmpV, 0);
  }

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

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

int main() {
  int n, m, x;
  int money;
  int ans = -1;
  cin >> n >> m >> x;
  vector<int> c(n);
  vector<int> skill(m);
  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);
  }
  for (int bit = 0; bit < (1 << n); bit++) {
    for (int i = 0; i < m; i++) {
      skill.at(i) = 0;
    }
    money = 0;
    for (int j = 0; j < n; j++) {
      if (bit >> j & 1) {
        money += c.at(j);
        for (int k = 0; k < m; k++) {
          skill.at(k) += a.at(j).at(k);
        }
      }
    }
    sort(skill.begin(), skill.end());
    if (skill.at(0) >= x) {
      if (ans == -1)
        ans = money;
      else
        ans = min(ans, money);
    }
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int n, m, x;
  int money;
  int ans = -1, tmp = -1;
  cin >> n >> m >> x;
  vector<int> c(n);
  vector<int> skill(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);
  }
  for (int bit = 0; bit < (1 << n); bit++) {
    for (int i = 0; i < m; i++) {
      skill.at(i) = 0;
    }
    money = 0;
    for (int j = 0; j < n; j++) {
      if (bit >> j & 1) {
        money += c.at(j);
        for (int k = 0; k < m; k++) {
          skill.at(k) += a.at(j).at(k);
        }
      }
    }
    sort(skill.begin(), skill.end());
    if (skill.at(0) >= x) {
      if (tmp == -1)
        ans = money;
      else
        ans = min(tmp, money);
      tmp = ans;
    }
  }
  cout << ans << endl;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
// #define ll long long
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int(i) = (int)(n)-1; (i) >= 0; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define all(x) (x).begin(), (x).end()
ll t1, t2, t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;

ll n, m, x;
vector<vector<ll>> vec(12, vector<ll>(12, 0));
vector<ll> c(12);
ll ans = INFLONG;

void dfs(ll num, ll cost, vector<ll> arr) {
  // cout << num << endl;
  if (num == n) {
    bool can = true;
    rep(i, m) {
      if (arr[i] < x) {
        can = false;
      }
    }
    if (can) {
      chmin(ans, cost);
    }
    return;
  }
  dfs(num + 1, cost, arr);
  rep(i, m) { arr[i] += vec[num][i]; }
  dfs(num + 1, cost + c[num], arr);
}

int main() {
  cin >> n >> m >> x;
  rep(i, n) {
    cin >> c[i];
    rep(j, m) { cin >> vec[i][j]; }
  }
  vector<ll> arr(m, 0);
  dfs(0, 0, arr);
  if (ans == INFLONG) {
    ans = -1;
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
// #define ll long long
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int(i) = (int)(n)-1; (i) >= 0; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define all(x) (x).begin(), (x).end()
ll t1, t2, t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;

ll n, m, x;
vector<vector<ll>> vec(12, vector<ll>(12, 0));
vector<ll> c(12);
ll ans = INFLONG;

void dfs(ll num, ll cost, vector<ll> arr) {
  // cout << num << endl;
  if (num == n) {
    bool can = true;
    rep(i, m) {
      if (arr[i] < x) {
        can = false;
      }
    }
    if (can) {
      chmin(ans, cost);
    }
    return;
  }
  dfs(num + 1, cost, arr);
  rep(i, m) { arr[i] += vec[num][i]; }
  dfs(num + 1, cost + c[num], arr);
}

int main() {
  cin >> n >> m >> x;
  rep(i, n) {
    cin >> c[i];
    rep(j, m) { cin >> vec[i][j]; }
  }
  vector<ll> arr(n, 0);
  dfs(0, 0, arr);
  if (ans == INFLONG) {
    ans = -1;
  }
  cout << ans << endl;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

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

int n, m, x;
vector<int> c;
vector<vector<int>> a;

int dfs() {
  int mn = pow(10, 8);
  //  	cout << mn << endl;
  rep(i, (1 << n)) {
    bitset<12> bt(i);
    int tp = 0;
    vector<int> ud(m, 0);
    bool fct = true;
    rep(j, n) {
      if (bt.test(j)) {
        tp += c.at(j);
        rep(k, m) ud.at(k) += a.at(j).at(k);
      }
    }
    rep(k, m) if (ud.at(k) < x) {
      fct = false;
      break;
    }
    if (fct)
      mn = min(tp, mn);
  }
  return mn;
}

int main() {
  cin >> n >> m >> x;
  c = vector<int>(n);
  a = vector<vector<int>>(n, vector<int>(m));
  rep(i, n) {
    cin >> c.at(i);
    rep(j, m) cin >> a.at(i).at(j);
  }
  rep(j, m) {
    int sm = 0;
    rep(i, n) sm += a.at(i).at(j);
    if (x > sm) {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << dfs() << endl;
}

Error: 0

Fixed submission:

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

int n, m, x;
vector<int> c;
vector<vector<int>> a;

int dfs() {
  int mn = pow(10, 6);
  rep(i, (1 << n)) {
    bitset<12> bt(i);
    int tp = 0;
    vector<int> ud(n, 0);
    bool fct = true;
    rep(j, n) {
      if (bt.test(j)) {
        tp += c.at(j);
        rep(k, m) ud.at(k) += a.at(j).at(k);
      }
    }
    rep(k, m) if (ud.at(k) < x) {
      fct = false;
      break;
    }
    if (fct)
      mn = min(tp, mn);
  }
  return mn;
}

int main() {
  cin >> n >> m >> x;
  c = vector<int>(n);
  a = vector<vector<int>>(n, vector<int>(m));
  rep(i, n) {
    cin >> c.at(i);
    rep(j, m) cin >> a.at(i).at(j);
  }
  rep(j, m) {
    int sm = 0;
    rep(i, n) sm += a.at(i).at(j);
    if (x > sm) {
      cout << -1 << endl;
      return 0;
    }
  }

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

#include <bits/stdc++.h>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#define int long long

using namespace std;
using namespace __gnu_pbds;

#define endl '\\n'

typedef long long ll;
typedef pair<int, int> pii;
// typedef tree<int,null_type,less<int>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 2e5 + 5;
const int maxp = 50;

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  int n, m, x;
  cin >> n >> m >> x;
  int a[n][m + 1];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  int sol = 999999999;
  for (int i = 0; i < (1 << n); i++) {
    vector<int> sum(m + 1, 0);
    for (int j = 0; j < n; j++) {
      if (i & (1 << j)) {
        for (int k = 0; k <= m; k++) {
          sum[k] += a[j][k];
        }
      }
    }

    bool f = 1;
    for (int k = 1; k <= m; k++) {
      if (sum[k] < x) {
        f = 0;
        break;
      }
    }
    if (f == 1) {
      sol = min(sol, sum[0]);
    }
  }
  if (sol == 999999999)
    sol = -1;
  cout << sol;

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define endl "\\n"
#define F first
#define S second
#define PB push_back
#define int long long

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;

const int maxn = 1e5;
const int OO = 1e18;
const int mod = 1e9 + 7;

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  //	freopen("name.in","r",stdin);
  //	freopen("name.out","w",stdout);

  int n, m, x;
  cin >> n >> m >> x;
  int ma[m + 2][n];
  for (int i = 0; i < n; i++)
    for (int j = 0; j <= m; j++)
      cin >> ma[i][j];

  int C = OO;
  for (int i = 0; i < (1 << n); i++) {
    int sum[m], cost = 0;
    for (int I = 0; I <= m; I++)
      sum[I] = 0;

    for (int j = 0; j < n; j++) {
      if (i & (1 << j)) {
        cost += ma[j][0];
        for (int k = 1; k <= m; k++)
          sum[k] += ma[j][k];
      }
    }
    bool f = 1;
    for (int z = 1; z <= m; z++) {
      if (sum[z] < x)
        f = 0;
    }
    if (f)
      C = min(C, cost);
  }
  if (C == OO)
    C = -1;
  cout << C;

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

#include <iostream>
using namespace std;
int minimalMoney;
int numOfBook, numOfA, underIndex;
int num[20][20];
int dp[20];

int calculate() {
  int temp;
  for (int i = 1; i <= numOfA; i++) {
    temp = 0;
    for (int j = 1; j <= numOfBook; j++) {
      if (dp[j] == 1) {
        temp += num[j][i];
      }
    }
    if (temp < underIndex) {
      return -1;
    }
  }
  temp = 0;
  for (int i = 1; i <= numOfBook; i++) {
    if (dp[i] == 1)
      temp += num[i][0];
  }
  return temp;
}

void decide(int start, int end) {
  if (start > end) {
    int temp = calculate();
    if (temp == -1)
      return;
    minimalMoney = temp < minimalMoney ? temp : minimalMoney;
  } else {
    dp[start] = 0;
    decide(start + 1, end);
    dp[start] = 1;
    decide(start + 1, end);
  }
}

int main() {
  cin >> numOfBook >> numOfA >> underIndex;
  for (int i = 1; i <= numOfBook; i++) {
    for (int j = 0; j <= numOfA; j++) {
      cin >> num[i][j];
    }
    dp[i] = 1;
  }
  minimalMoney = 1;
  for (int i = 1; i <= numOfBook; i++) {
    minimalMoney += num[i][0];
  }
  int temp = minimalMoney;
  decide(1, numOfBook);
  if (temp == minimalMoney) {
    cout << -1;
  } else {
    cout << minimalMoney;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int minimalMoney;
int numOfBook, numOfA, underIndex;
int num[20][20];
int dp[20];
int index[20];
bool minimalMoneyCheck(int nowMoney, int removedNum) {
  dp[removedNum] = 0;
  for (int i = 1; i <= numOfA; i++) {
    index[i] -= num[removedNum][i];
    if (index[i] < underIndex) {
      for (int j = 1; j <= i; j++) {
        index[j] += num[removedNum][j];
      }
      return false;
    }
  }
  minimalMoney = nowMoney - num[removedNum][0] < minimalMoney
                     ? nowMoney - num[removedNum][0]
                     : minimalMoney;
  for (int i = 1; i <= numOfBook; i++) {
    if (dp[i] != 0) {
      dp[i] = 0;
      minimalMoneyCheck(nowMoney - num[removedNum][0], i);
      dp[i] = 1;
    }
  }
  dp[removedNum] = 1;
  for (int i = 1; i <= numOfA; i++) {
    index[i] += num[removedNum][i];
  }
  return true;
}
int main() {
  cin >> numOfBook >> numOfA >> underIndex;

  for (int i = 1; i <= numOfBook; i++) {
    for (int j = 0; j <= numOfA; j++) {
      cin >> num[i][j];
    }
    dp[i] = 1;
  }
  minimalMoney = 0;
  for (int i = 1; i <= numOfBook; i++) {
    minimalMoney += num[i][0];
  }
  int temp = 0;
  for (int i = 1; i <= numOfA; i++) {
    temp = 0;
    index[i] = 0;
    for (int j = 1; j <= numOfBook; j++) {
      temp += num[j][i];
    }
    if (temp < underIndex) {
      cout << -1;
      return 0;
    }
    index[i] = temp;
  }
  int money = minimalMoney;
  for (int i = 1; i <= numOfBook; i++) {
    minimalMoneyCheck(money, i);
  }
  cout << minimalMoney;
}
Problem p02683 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int choose(vector<vector<int>> stores, int i, int n, int m, vector<int> books,
           int cost) {
  if (i == n) {
    for (int j = 1; j < m + 1; j++) {
      if (books[j] > 0) {
        return INT_MAX;
      }
    }
    return cost;
  }
  int ans1 = choose(stores, i + 1, n, m, books, cost);
  for (int j = 0; j < m + 1; j++) {
    books[j] -= stores[i][j];
  }
  int ans2 = choose(stores, i + 1, n, m, books, cost + stores[i][0]);
  return min(ans1, ans2);
}

void solve() {
  int n, m, x;
  cin >> n >> m >> x;

  vector<vector<int>> stores(n);
  for (int i = 0; i < n; i++) {
    for (int j = 0, ele; j < m + 1; j++) {
      cin >> ele;
      stores[i].push_back(ele);
    }
  }
  vector<int> books(m + 1, x);
  int ans = choose(stores, 0, n, m, books, 0);
  if (ans == INT_MAX) {
    cout << -1;
  } else {
    cout << ans;
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  solve();
  return 0;
}

Error: TLE

Fixed submission:

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

bool possible(vector<int> books, int m, int x) {
  for (int j = 1; j < m + 1; j++) {
    if (books[j] < x) {
      return false;
    }
  }
  return true;
}

bool allVisited(vector<bool> visited, int n) {
  for (int i = 0; i < n; i++) {
    if (!visited[i]) {
      return false;
    }
  }
  return true;
}

int choose(vector<vector<int>> stores, int n, int m, int x,
           vector<bool> visited, vector<int> books, int cost) {
  if (possible(books, m, x)) {
    return cost;
  }
  if (allVisited(visited, n)) {
    return INT_MAX;
  }
  int minCost = INT_MAX;
  for (int i = 0; i < n; i++) {
    if (!visited[i]) {
      visited[i] = true;
      for (int j = 1; j < m + 1; j++) {
        books[j] += stores[i][j];
      }
      int ans = choose(stores, n, m, x, visited, books, cost + stores[i][0]);
      minCost = min(ans, minCost);
      for (int j = 1; j < m + 1; j++) {
        books[j] -= stores[i][j];
      }
      visited[i] = false;
    }
  }
  return minCost;
}

void solve() {
  int n, m, x;
  cin >> n >> m >> x;

  vector<vector<int>> stores(n);
  for (int i = 0; i < n; i++) {
    for (int j = 0, ele; j < m + 1; j++) {
      cin >> ele;
      stores[i].push_back(ele);
    }
  }
  vector<bool> visited(n, false);
  vector<int> books(m + 1, 0);
  int ans = choose(stores, n, m, x, visited, books, 0);
  if (ans == INT_MAX) {
    cout << -1;
  } else {
    cout << ans;
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  solve();
  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
int c[13], a[13][13];
int main() {
  ios::sync_with_stdio(false);
  int n, m, x, maxx = 10000000, k, sf = 0;
  cin >> n >> m >> x;
  for (int i = 1; i <= n; i++) {
    cin >> c[i];
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  int book[n + 1], understand[m + 1], pd = 0, dj = 0;
  for (int i = 1; i <= n; i++) {
    book[i] = 0;
  }
  while (book[0] != 1) {
    for (int i = 1; i <= m; i++) {
      understand[i] = 0;
    }
    dj = 0;
    pd = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        if (book[i] == 1)
          understand[j] += a[i][j];
      }
    }
    for (int i = 1; i <= m; i++) {
      if (understand[i] < x)
        pd = 1;
    }
    for (int i = 1; i <= n; i++)
      if (book[i] == 1)
        dj += c[i];
    if (pd == 0 && dj <= maxx) {
      maxx = dj;
      sf = 1;
    }
    int k = n;
    while (book[k] != 0) {
      k--;
    }
    book[k] = 1;
    for (int i = k + 1; i <= n; i++) {
      book[i] = 0;
    }
  }
  if (sf == 0)
    cout << "-1";
  else
    cout << maxx;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
int c[13], a[13][13];
int main() {
  ios::sync_with_stdio(false);
  int n, m, x, maxx = 10000000, k, sf = 0;
  cin >> n >> m >> x;
  for (int i = 1; i <= n; i++) {
    cin >> c[i];
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  int book[n + 1], understand[m + 1], pd = 0, dj = 0;
  for (int i = 1; i <= n; i++) {
    book[i] = 0;
  }
  while (book[0] != 1) {
    for (int i = 1; i <= m; i++) {
      understand[i] = 0;
    }
    dj = 0;
    pd = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        if (book[i] == 1)
          understand[j] += a[i][j];
      }
    }
    for (int i = 1; i <= m; i++) {
      if (understand[i] < x)
        pd = 1;
    }
    for (int i = 1; i <= n; i++)
      if (book[i] == 1)
        dj += c[i];
    if (pd == 0 && dj <= maxx) {
      maxx = dj;
      sf = 1;
    }
    int k = n;
    while (book[k] != 0) {
      k--;
    }
    book[k] = 1;
    for (int i = k + 1; i <= n; i++) {
      book[i] == 0;
    }
  }
  if (sf == 0)
    cout << "-1";
  else
    cout << maxx;
  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> C(13); // 値段の配列,0-indexなのに注意
  vector<vector<int>> A(
      13, vector<int>(13)); // M冊の，N個のアルゴリズムの情報が入った配列

  // 入力
  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 minC =
      10000000; // 理解度を十分満たす最小の合計金額　十分大きい数字にしておく

  // bit全探索

  for (int bit = 0; bit < (1 << N); bit++) {
    // 試行回数bit回目
    vector<int> AL(M); // アルゴリズムの理解度を入れる配列．M種類
    int sum = 0;       // 合計金額を入れる
    for (int i = 0; i < N; i++) {
      if (bit &
          (1 << i)) { // i番目のフラグが立っていたら，つまりi番目の本を買ったら
        sum += C.at(i); // 金額を加算;
        for (int j = 0; j < M; j++) {
          AL.at(j) += A.at(i).at(j); // 理解度を増やす
        }
      }
    }
    // ここまでにループで，どの本を買って金額がいくらになり，理解度がどれだけ増えたかわかっている
    bool flag = 0;
    for (int i = 0; i < M; i++) {
      if (AL.at(i) < X)
        flag = 1;
    }
    if (!flag)
      minC = min(minC, sum); // 条件を満たしかつ最小の金額ならば更新する
  }
  if (minC == 10000000)
    cout << -1 << endl;
  else
    cout << minC << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> C(N); // 値段の配列,0-indexなのに注意
  vector<vector<int>> A(
      M, vector<int>(N)); // M冊の，N個のアルゴリズムの情報が入った配列

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

  int minC =
      10000000; // 理解度を十分満たす最小の合計金額　十分大きい数字にしておく

  // bit全探索

  for (int bit = 0; bit < (1 << N); bit++) {
    // 試行回数bit回目
    vector<int> AL(M); // アルゴリズムの理解度を入れる配列．M種類
    int sum = 0;       // 合計金額を入れる
    for (int i = 0; i < N; i++) {
      if (bit &
          (1 << i)) { // i番目のフラグが立っていたら，つまりi番目の本を買ったら
        sum += C[i];  // 金額を加算;
        for (int j = 0; j < M; j++) {
          AL[j] += A[i][j]; // 理解度を増やす
        }
      }
    }
    // ここまでにループで，どの本を買って金額がいくらになり，理解度がどれだけ増えたかわかっている
    bool flag = 0;
    for (int i = 0; i < M; i++) {
      if (AL[i] < X)
        flag = 1;
    }
    if (!flag)
      minC = min(minC, sum); // 条件を満たしかつ最小の金額ならば更新する
  }
  if (minC == 10000000)
    cout << -1 << endl;
  else
    cout << minC << endl;
}