alexjercan/bugnet huggingface dataset:
Problem p02683 (C++) — buggy submission, verdict: Time Limit Exceeded

// c++ テンプレ
#include <bits/stdc++.h>
using namespace std;

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
priority_queue<llint, vector<llint>, greater<llint>> que;
priority_queue<llint> Que;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

void solve() {
  llint x, n, m;
  llint a[15][15];
  cin >> n >> m >> x;
  llint c[15];
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  llint N = 1 << n;
  llint ans = inf;
  llint sum[15];
  llint cost;
  for (int i = 0; i < N; i++) {
    cost = 0;
    for (int j = 1; j <= m; j++)
      sum[j] = 0;
    for (int j = 0; j < n; j++) {
      if (!(i & (1 << j)))
        continue;
      cost += c[j];
      for (int k = 1; k <= m; k++)
        sum[k] += a[j][k];
    }
    bool f = true;
    for (int j = 1; j <= m; j++) {
      if (sum[j] < x)
        f = false;
    }
    if (f)
      ans = min(cost, ans);
  }
  if (ans == inf)
    cout << -1 << endl;
  else
    cout << ans << endl;
}

int main() {
  solve();
  return 0;
}


Error: TLE

Fixed submission:

// c++ テンプレ
#include <bits/stdc++.h>
using namespace std;

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
priority_queue<llint, vector<llint>, greater<llint>> que;
priority_queue<llint> Que;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

void solve() {
  llint x, n, m;
  llint a[15][15];
  cin >> n >> m >> x;
  vector<llint> c(n);
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  llint N = 1 << n;
  llint ans = inf;
  vector<llint> sum(m + 1);
  llint cost;
  for (int i = 0; i < N; i++) {
    cost = 0;
    for (int j = 1; j <= m; j++)
      sum[j] = 0;
    for (int j = 0; j < n; j++) {
      if (!(i & (1 << j)))
        continue;
      cost += c[j];
      for (int k = 1; k <= m; k++)
        sum[k] += a[j][k];
    }
    bool f = true;
    for (int j = 1; i <= m; j++) {
      if (sum[j] < x)
        f = false;
    }
    if (f)
      ans = min(cost, ans);
  }
  if (ans == inf)
    cout << -1 << endl;
  else
    cout << ans << endl;
}

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

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

#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep2(i, s, n) for (long long i = (s); i < (long long)(n); i++)
#define repi(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2i(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL << 60);
const int INFi = (1 << 29);

bool in(vll l, ll p) {
  rep(i, l.size()) if (l[i] == p) return true;
  return false;
}

int main() {

  ll n, m, x;
  cin >> n >> m >> x;
  vll c(n);
  vvll a(n, vll(m));
  rep(i, n) {
    cin >> c[i];
    rep(j, m) { cin >> a[i][j]; }
  }

  ll min_price = INF;
  rep(i, 1 << n) {
    bitset<12> bs(i);
    vll skill(m, 0);
    ll price = 0;
    rep(j, n) {
      if (bs.test(j)) {
        price += c[j];
        rep(k, m) { skill[k] += a[j][k]; }
      }
    }

    bool f = true;
    rep(k, m) {
      if (skill[k] >= x) {
        f &= true;
      } else {
        f &= false;
        break;
      }
    }
    if (f)
      min_price = min(min_price, price);
  }

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

  return 0;
}

Error: 0

Fixed submission:

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

#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep2(i, s, n) for (long long i = (s); i < (long long)(n); i++)
#define all(v) v.begin(), v.end()

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;

const ll INF = (1LL << 60);

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];
    }
  }

  vector<int> ans(n, 0);
  int kin = 0;
  int mn = (1 << 30);
  bool flg = true;
  for (int i = 0; i < (1 << n); i++) {
    bitset<12> bs(i);

    for (int j = 0; j < n; j++) {
      if (bs.test(j)) {
        for (int k = 0; k < m; k++) {
          if (ans[k] >= x)
            continue;
          ans[k] += a[j][k];
        }
        kin += c[j];
      }
    }

    bool flg = true;
    for (int j = 0; j < m; j++) {
      flg &= !!(ans[j] >= x);
      ans[j] = 0;
    }
    if (flg) {
      mn = min(mn, kin);
    }

    kin = 0;
  }

  if (mn == (1 << 30))
    mn = -1;
  cout << mn << endl;

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

#include "algorithm"
#include "bitset"
#include "cassert"
#include "climits"
#include "cmath"
#include "cstdio"
#include "ctime"
#include "functional"
#include "iomanip"
#include "iostream"
#include "list"
#include "map"
#include "numeric"
#include "queue"
#include "random"
#include "set"
#include "stack"
#include "string"
#include "unordered_map"
#include "unordered_set"

using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
const int INF = 1001001001;

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m));
  rep(i, n) {
    cin >> c[i];
    rep(j, m) { cin >> a[i][j]; }
  }
  // 参考書の買い方は2^12=4096通り以下なので、全探索する。
  int ans = INF;
  rep(i, 1 << 12) {
    // 参考書を買うor買わないの情報now
    bitset<12> now = i;
    // 払ったお金cost
    int cost = 0;
    // 高橋くんのそれぞれのアルゴリズムに対する理解度
    vector<int> skill(m);
    // j番目の参考書に注目する。
    rep(j, n) {
      // nowのj番目が1だったらj番目の参考書を買う
      if (now.test(j)) {
        cost += c[j];
        // j番目の参考書を買ったときに得られる各アルゴリズムへの理解度を加える
        rep(k, m) skill[k] += a[j][k];
      }
    }
    bool flag = true;
    // 一つでもx未満の理解度が存在する場合は、flagを折る
    rep(j, m) {
      if (skill[j] < x)
        flag = false;
    }
    if (flag) {
      ans = min(ans, cost);
    }
  }
  if (ans == INF)
    ans = -1;
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include "algorithm"
#include "bitset"
#include "cassert"
#include "climits"
#include "cmath"
#include "cstdio"
#include "ctime"
#include "functional"
#include "iomanip"
#include "iostream"
#include "list"
#include "map"
#include "numeric"
#include "queue"
#include "random"
#include "set"
#include "stack"
#include "string"
#include "unordered_map"
#include "unordered_set"

using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  int n, m, x; // n texts, m algorythms, more than or equal to x points.
  cin >> n >> m >> x;
  vector<pair<int, vector<int>>> book(n);
  rep(i, n) {
    int c;
    cin >> c;
    vector<int> a(n);
    rep(i, m) cin >> a[i];
    pair<int, vector<int>> pair = make_pair(c, a);
    book[i] = pair;
  }
  int ans = 12 * 100000 + 1;
  for (int pattern = 0; pattern < (1 << n); pattern++) {
    bool check = true;
    vector<int> score(m);
    int cost = 0;
    bitset<12> now(pattern);
    rep(i, 12) {
      if (i >= n)
        break;
      if (now[i] == 1) {
        rep(j, m) score[j] += book[i].second[j];
        cost += book[i].first;
      }
    }
    rep(i, m) {
      if (score[i] < x)
        check = false;
    }
    if (check)
      ans = min(ans, cost);
    if (pattern == (1 << n) - 1 && ans == 12 * 100000 + 1)
      ans = -1;
  }
  cout << ans << endl;
  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1001001001

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

int main() {
  ll N, M, X;
  cin >> N >> M >> X;
  vector<ll> C(N);
  vector<vector<ll>> A;
  for (ll i = 0; i < N; ++i) {
    cin >> C[i];
    vector<ll> temp_a(M);
    for (ll j = 0; j < M; ++j) {
      cin >> temp_a[j];
    }
    A.push_back(temp_a);
  }
  solve(N, M, X, C, A);
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAX = 1e18;

void solve(ll N, ll M, ll X, vector<ll> C, vector<vector<ll>> A) {
  ll ans = MAX;
  vector<ll> L(N, 0);
  for (int i = 0; i < N; ++i)
    L[i] = i;
  do {
    vector<ll> S(M, 0);
    ll total = 0;
    for (int i = 0; i < N; ++i) {
      vector<int> check(M, 1);
      for (int j = 0; j < M; ++j) {
        S[j] += A[L[i]][j];
        if (S[j] < X)
          check[j] = 0;
      }
      // cout << i << " " << accumulate(check.begin(), check.end(), 0) << " " <<
      // check.size() << " " << ans << " " << total << endl;
      total += C[L[i]];
      if (accumulate(check.begin(), check.end(), 0) == check.size())
        ans = min(ans, total);
    }
  } while (next_permutation(L.begin(), L.end()));
  if (ans == MAX)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return;
}

int main() {
  ll N, M, X;
  cin >> N >> M >> X;
  vector<ll> C(N);
  vector<vector<ll>> A;
  for (ll i = 0; i < N; ++i) {
    cin >> C[i];
    vector<ll> temp_a(M);
    for (ll j = 0; j < M; ++j) {
      cin >> temp_a[j];
    }
    A.push_back(temp_a);
  }
  solve(N, M, X, C, A);
  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

const long long INF = 1e18;
int n, m;
long long x;
vector<long long> C(15, 0);
vector<vector<long long>> A(15, vector<long long>(15, 0));

int main() {
  cin >> n >> m >> x;
  for (int i = 0; i < n; ++i) {
    cin >> C.at(i);
    for (int j = 0; j < m; ++j) {
      cin >> A.at(i).at(j);
    }
  }

  long long ansmin = INF;
  for (int bit = 0; bit < (1 << n); ++bit) {
    long long cans = 0;
    vector<long long> AA(m, 0);
    for (int i = 0; i < n; ++i) {
      if (bit & (1 << i)) {
        cans += C.at(i);
        for (int j = 0; j < m; ++j) {
          AA.at(j) += A.at(i).at(j);
        }
      }
    }

    bool flg = true;
    for (int i = 0; i < m; ++i) {
      if (AA.at(i) < x) {
        flg = false;
        break;
      }
    }
    if (flg) {
      chmin(ansmin, cans);
    }
  }

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

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

const long long INF = 1e18;
int n, m;
long long x;
vector<long long> C(15, 0);
vector<vector<long long>> A(15, vector<long long>(15, 0));

int main() {
  cin >> n >> m >> x;
  for (int i = 0; i < n; ++i) {
    cin >> C.at(i);
    for (int j = 0; j < m; ++j) {
      cin >> A.at(i).at(j);
    }
  }

  long long ansmin = INF;
  for (int bit = 0; bit < (1 << n); ++bit) {
    long long cans = 0;
    vector<long long> AA(n, 0);
    for (int i = 0; i < n; ++i) {
      if (bit & (1 << i)) {
        cans += C.at(i);
        for (int j = 0; j < m; ++j) {
          AA.at(j) += A.at(i).at(j);
        }
      }
    }

    bool flg = true;
    for (int i = 0; i < m; ++i) {
      if (AA.at(i) < x) {
        flg = false;
        break;
      }
    }
    if (flg) {
      chmin(ansmin, cans);
    }
  }

  if (ansmin == INF) {
    cout << -1 << endl;
  } else {
    cout << ansmin << endl;
  }
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define oo 0x3f3f3f3f
#define ooLL 0x3f3f3f3f3f3f3f3f
#define fastio()                                                               \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL)
const int mod = 1e9 + 7;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
int n, m, x;

int main() {
  scanf("%d%d%d", &n, &m, &x);
  int grid[n][m], costs[n];
  for (int i = 0; i < n; ++i) {
    scanf("%d", &costs[i]);
    for (int j = 0; j < m; ++j) {
      scanf("%d", &grid[i][j]);
    }
  }

  int ans = oo;
  for (int i = 0; i < (1 << n); ++i) {
    vector<int> s(m, 0);
    int cst = 0;
    for (int j = 0; j < n; ++j) {
      if (i & (1 << j))
        continue;
      cst += costs[j];
      for (int k = 0; k < m; ++k)
        s[k] += grid[j][k];
    }

    bool valid = true;
    for (int k = 0; k < m && valid; ++k) {
      if (s[k] < x)
        valid = false;
    }
    if (valid)
      ans = min(ans, cst);
  }

  printf("%d\\n", ans == oo ? -1 : ans);

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define oo 0x3f3f3f3f
#define ooLL 0x3f3f3f3f3f3f3f3f
#define fastio()                                                               \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL)
const int mod = 1e9 + 7;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
int n, m, x;

int main() {
  scanf("%d%d%d", &n, &m, &x);
  int grid[n][m], costs[n];
  vector<vector<ii>> grid2(m, vector<ii>(n));
  for (int i = 0; i < n; ++i) {
    scanf("%d", &costs[i]);
    for (int j = 0; j < m; ++j) {
      scanf("%d", &grid[i][j]);
    }
  }

  int ans = oo;
  for (int i = 0; i < (1 << n); ++i) {
    vector<int> s(n, 0);
    int cst = 0;
    for (int j = 0; j < n; ++j) {
      if (i & (1 << j))
        continue;
      cst += costs[j];
      for (int k = 0; k < m; ++k)
        s[k] += grid[j][k];
    }

    bool valid = true;
    for (int k = 0; k < m && valid; ++k) {
      if (s[k] < x)
        valid = false;
    }
    if (valid)
      ans = min(ans, cst);
  }

  printf("%d\\n", ans == oo ? -1 : ans);

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

#include <iostream>

#define INF 12345678
using namespace std;

int main() {
  int n, m, x;
  int c[12];
  int a[12][12];
  int i, j, k, l;

  int knowledge[12] = {0};

  int buy_bool[12];

  int expo_n, i_tmp, price_sum, price_min;

  bool archive_flg = true;

  price_min = INF;

  cin >> n >> m >> x;

  for (i = 0; i < n; i++) {
    cin >> c[i];
    for (j = 0; j < m; j++)
      cin >> a[i][j];
  }
  expo_n = 1;
  for (i = 0; i < n; i++)
    expo_n *= 2;

  for (i = 1; i < expo_n; i++) {
    i_tmp = i;
    for (j = 0; j < n; j++) {
      buy_bool[j] = 0;
      buy_bool[j] = i_tmp % 2;
      i_tmp /= 2;
    }

    for (j = 0; j < m; j++)
      knowledge[j] = 0;

    price_sum = 0;
    for (j = 0; j < n; j++) {
      if (buy_bool[j] != 0) {
        price_sum += c[j];
        for (k = 0; k < m; k++)
          knowledge[k] += a[j][k];
      }
    }

    archive_flg = true;
    for (j = 0; j < m; j++) {
      if (knowledge[j] < x) {
        archive_flg = false;
      }
    }

    if (archive_flg && price_min > price_sum) {
      price_min = price_sum;
    }
  }

  if (price_min == INF)
    cout << -1 << endl;
  else
    cout << price_min << endl;
  return 0;
}


Error: WA

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int n, m, x;
  int c[12];
  int a[12][12];
  int i, j, k;

  int knowledge[12] = {0};

  int buy_bool[12];

  int expo_n, i_tmp, price_sum, price_min = -1;

  bool archive_flg = true;

  cin >> n >> m >> x;

  for (i = 0; i < n; i++) {
    cin >> c[i];
    for (j = 0; j < m; j++)
      cin >> a[i][j];
  }
  expo_n = 1;
  for (i = 0; i < n; i++)
    expo_n *= 2;

  for (i = 0; i < expo_n; i++) {
    i_tmp = i;
    for (j = 0; j < n; j++) {
      buy_bool[j] = 0;
      buy_bool[j] = i_tmp % 2;
      i_tmp /= 2;
    }
    price_sum = 0;
    for (j = 0; j < n; j++) {
      if (buy_bool[j] != 0)
        price_sum += c[j];
    }
    if (price_min == -1 || price_sum < price_min) {
      for (j = 0; j < n; j++)
        knowledge[j] = 0;
      if (buy_bool[i] != 0) {
        for (k = 0; k < m; k++)
          knowledge[j] += a[j][k];
      }
    }
    archive_flg = true;
    for (j = 0; j < n; j++) {
      if (knowledge[j] < x) {
        archive_flg = false;
        break;
      }
    }
    if (archive_flg)
      price_min = price_sum;
  }

  cout << price_min << endl;

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

#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; i++)
#define inf 1000000000
typedef long long ll;
int n, m;
ll x;

vector<int> c(200);
vector<vector<int>> a(200, vector<int>(200));
ll sum = 0;
bool ok = true;
ll MIN = inf;
void dfs(int now, vector<ll> sw, ll cost) {
  ok = true;
  if (now == n) {
    for (int i = 0; i < m; i++) {
      if (sw[i] < x) {
        ok = false;
        return;
      }
    }
    MIN = min(MIN, cost);
    return;
  }

  dfs(now + 1, sw, cost);
  for (int j = 0; j < m; j++) {
    sw[j] += a[now][j];
  }
  cost += c[now];
  dfs(now + 1, sw, cost);
}

int main() {
  cin >> n >> m >> x;
  vector<ll> skill(n + 100, 0);

  rep(i, 0, n) {
    cin >> c[i];
    rep(j, 0, m) { cin >> a[i][j]; }
  }
  ll co = 0;
  dfs(0, skill, co);

  if (ok) {
    cout << MIN << endl;
  } else {
    cout << -1 << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; i++)
#define inf 1000000000
typedef long long ll;
int n, m;
ll x;

vector<int> c(100);
vector<vector<int>> a(100, vector<int>(100));
ll sum = 0;
bool ok = true;
ll MIN = inf;
void dfs(int now, vector<ll> sw, ll cost) {
  ok = true;
  if (now == n) {
    for (int i = 0; i < m; i++) {
      if (sw[i] < x) {
        ok = false;
        return;
      }
    }
    MIN = min(MIN, cost);
    return;
  }

  dfs(now + 1, sw, cost);
  for (int j = 0; j < m; j++) {
    sw[j] += a[now][j];
  }
  cost += c[now];
  dfs(now + 1, sw, cost);
}

int main() {
  cin >> n >> m >> x;
  vector<ll> skill(n + 5, 0);

  rep(i, 0, n) {
    cin >> c[i];
    rep(j, 0, m) { cin >> a[i][j]; }
  }
  ll c = 0;
  dfs(0, skill, c);

  if (ok) {
    cout << MIN << endl;
  } else {
    cout << -1 << endl;
  }

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

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int a[12][12];
const int INF = 1001001001;

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

  rep(i, n) {
    cin >> c[i];
    rep(j, m) cin >> a[i][j];
  }

  int ans = INF;

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

  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

#define rep(i, n) for (int i; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int a[12][12];
const int INF = 1001001001;

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

  rep(i, n) {
    cin >> c[i];
    rep(j, m) cin >> a[i][j];
  }

  int ans = INF;

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

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

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

int main() {

  ll N, M, X;
  ll tot = 0;
  ll ans = INF;

  cin >> N >> M >> X;

  vector<vector<ll>> A(N, vector<ll>(M));
  vector<ll> C(N);

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

  for (ll i = 0; i < (1 << N); ++i) {

    tot = 0;
    vector<ll> a(M);

    for (ll j = 0; j < N; ++j) {

      if ((i >> j) & 1) {

        tot = tot + C[j];
        for (ll k = 0; k < M; ++k)
          a[k] += A[j][k];
      }
    }

    bool flg = true;

    for (ll j = 0; j < M; ++j)
      if (a[j] < X)
        flg = false;
    if (flg)
      ans = std::min(ans, tot);
  }

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

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

typedef pair<ll, bool> Pair;

ll N, M, X;
vector<ll> a;
vector<vector<ll>> A;
vector<ll> C;
ll tot = 0;
ll ans = INF;

int main() {

  cin >> N >> M >> X;

  C = vector<ll>(N);
  A = vector<vector<ll>>(N, vector<ll>(M));
  a = vector<ll>(M);

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

  vector<ll> v;

  for (ll i = 0; i < N; ++i)
    v.push_back(i);

  do {

    tot = 0;
    for (ll i = 0; i < M; ++i)
      a[i] = 0;

    for (ll i = 0; i < N; ++i) {

      bool flg = true;

      tot = tot + C[v[i]];

      for (ll j = 0; j < M; ++j) {

        a[j] += A[v[i]][j];

        if (a[j] < X) {
          flg = false;
        }
      }

      if (flg) {
        ans = std::min(ans, tot);
        break;
      }
    }

  } while (next_permutation(v.begin(), v.end()));

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

  return 0;
}