Problem p02683 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
//                    #include <ext/pb_ds/assoc_container.hpp>
//                    #include <ext/pb_ds/tree_policy.hpp>

using ll = long long;
using ld = long double;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define per(i, a, n) for (ll i = (n - 1); i >= (a); i--)
#define F first
#define S second
#define maxx(a, b) a = max(a, b)
#define minn(a, b) a = min(a, b)
#define db(x) cerr << #x << " = " << x << endl
#define N 1111111
#define mod 1000000007
#define rt return
#define inf 123456789123456789ll

using namespace std;
random_device rd;
mt19937 mt(rd());
//                    using namespace __gnu_pbds;
//
//                    typedef tree<pair<ll,ll>, null_type, less<pair<ll,ll>>,
//                    rb_tree_tag, tree_order_statistics_node_update>
//                    indexed_set;

#define error(args...)                                                         \\
  {                                                                            \\
    string _s = #args;                                                         \\
    replace(_s.begin(), _s.end(), ',', ' ');                                   \\
    stringstream _ss(_s);                                                      \\
    istream_iterator<string> _it(_ss);                                         \\
    err(_it, args);                                                            \\
  }

void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}

ll modlaber(ll a, ll m = mod) { rt((a + m) % m + m) % m; }

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

  ll n, m, ch;
  cin >> n >> m >> ch;

  bitset<15> b;

  vector<ll> c(n);
  vector<vector<ll>> v(n, vector<ll>(m));

  rep(i, 0, n) {
    cin >> c[i];
    for (auto &x : v[i])
      cin >> x;
  }

  ll ans = inf;

  rep(i, 0, 1 << n) {
    b = i;
    vector<ll> temp(m);
    ll ras = 0;
    rep(j, 0, n) {
      if (b[j]) {
        rep(k, 0, m) temp[k] += v[j][k];
        ras += c[j];
      }
    }
    if (*min_element(begin(temp), end(temp)) >= ch)
      minn(ans, ras);
  }

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

  rt 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using ll = long long;
using ld = long double;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define per(i, a, n) for (ll i = (n - 1); i >= (a); i--)
#define F first
#define S second
#define maxx(a, b) a = max(a, b)
#define minn(a, b) a = min(a, b)
#define db(x) cerr << #x << " = " << x << endl
#define N 1111111
#define mod 1000000007
#define rt return
#define inf 123456789123456789ll

using namespace std;
random_device rd;
mt19937 mt(rd());
using namespace __gnu_pbds;

typedef tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;

#define error(args...)                                                         \\
  {                                                                            \\
    string _s = #args;                                                         \\
    replace(_s.begin(), _s.end(), ',', ' ');                                   \\
    stringstream _ss(_s);                                                      \\
    istream_iterator<string> _it(_ss);                                         \\
    err(_it, args);                                                            \\
  }

void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}

ll modlaber(ll a, ll m = mod) { rt((a + m) % m + m) % m; }

int n, m, x;
vector<int> v[15];
int c[15];
int ans = INT_MAX;
int used[22];
int temp[22];

void rec(int qoldi, int sum) {
  int mi = INT_MAX;
  rep(i, 0, m) minn(mi, temp[i]);
  if (mi >= x) {
    minn(ans, sum);
    rt;
  }
  rep(i, 0, n) {
    if (!used[i]) {
      used[i] = 1;
      rep(j, 0, m) temp[j] += v[i][j];
      rec(qoldi - 1, sum + c[i]);
      rep(j, 0, m) temp[j] -= v[i][j];
      used[i] = 0;
    }
  }
}

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

  cin >> n >> m >> x;
  rep(i, 0, n) {
    cin >> c[i];
    v[i].resize(m);
    for (auto &y : v[i])
      cin >> y;
  }

  rep(i, 1, n + 1) rec(i, 0);

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

  rt 0;
}