prithivMLmods/Coder-Stat huggingface dataset:
Problem p02682 (Python)

Buggy submission (status: Time Limit Exceeded):
a, b, c, k = map(int, input().split())

ans = 0

for i in range(k):
    if a >= 1:
        ans += 1
        a -= 1
    elif b >= 1:
        b -= 1
        pass
    else:
        ans -= 1
print(ans)


Fixed submission:
a, b, c, k = map(int, input().split())

if k <= a:
    print(k)
elif k - a > b:
    print(-1 * ((k - a) - b) + a)
else:
    print(a)
Problem p02682 (Python)

Buggy submission (status: Runtime Error):
A, B, C, K = map(int, input().spliit())
if K <= A:
    print(K)

elif K <= A + B:
    print(A)

else:
    print(A - (K - (A + B)))


Fixed submission:
A, B, C, K = map(int, input().split())
if K <= A:
    print(K)

elif K <= A + B:
    print(A)

else:
    print(A - (K - (A + B)))
Problem p02682 (Python)

Buggy submission (status: Runtime Error):
def main():
    A, B, C, K = map(int, input().split())
    li = [1] * A
    li += [0] * B
    li += [-1] * C
    print(sum(li[:K]))


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    A, B, _, K = map(int, input().split())
    if A > K:
        print(K)
        quit()
    print(A - max([0, K - A - B]))


if __name__ == "__main__":
    main()
Problem p02682 (Python)

Buggy submission (status: Runtime Error):
A, B, C, K = (int(x) for x in input().split())

a = [1] * A
b = [0] * B
c = [-1] * C

X = a + b + c
print(sum(X[:K]))


Fixed submission:
A, B, C, K = map(int, input().split())
if K <= A:
    print(K)
elif K <= A + B:
    print(A)
else:
    print(2 * A + B - K)
Problem p02682 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  int k, a, b, c, sum = 0;
  cin >> a >> b >> c >> k;
  for (int i = 0; i < k; i++) {
    if (a > 0) {
      sum++;
      a--;
    } else if (a == 0 && b > 0)
      b--;
    else if (a == 0 && b == 0 && c > 0) {
      sum--;
      c--;
    }
  }
  cout << sum << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  int k, a, b, c, sum = 0;
  cin >> a >> b >> c >> k;
  if (k >= a) {
    k -= a;
    sum += a;
  } else {
    sum = k;
    k = 0;
  }

  if (k >= b) {
    k -= b;
  } else {
    k = 0;
  }

  if (k != 0) {
    sum -= k;
    k = 0;
  }
  cout << sum << endl;
  return 0;
}
Problem p02682 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long a, b, c, k, ans = 0;
  cin >> a >> b >> c >> k;
  long long total = a + b + c;
  if (k >= total)
    cout << a - c << endl;
  else {
    for (long long i = 0; i < k; i++) {
      if (a != 0) {
        ans++;
        a--;
      } else if (a == 0 && b != 0)
        b--;
      else if (a == 0 && b == 0 && c != 0) {
        ans--;
        c--;
      } else if (a == 0 && b == 0 && c == 0)
        break;
    }
    cout << ans << endl;
  }
}

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

int main() {
  long long a, b, c, k, ans = 0;
  cin >> a >> b >> c >> k;
  long long total = a + b + c;
  if (k >= total)
    cout << a - c << endl;
  else {
    int some = 0;
    some = k - a;
    if (some > 0) {
      ans = a;
      for (long long i = 0; i < some; i++) {
        if (b != 0)
          b--;
        else if (b == 0 && c != 0) {
          ans--;
          c--;
        }
      }
    } else
      ans = k;
    cout << ans << endl;
  }
}
Problem p02682 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)

int main() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  vector<ll> p(a + b + c);
  for (ll i = 0; i < a; i++)
    p[i] = 1;
  for (ll i = a; i < a + b; i++)
    p[i] = 0;
  for (int i = a + b; i < a + b + c; i++)
    p[i] = -1;
  ll ans = 0;
  rep(i, k) ans += p[i];
  cout << ans << "\n";
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)

int main() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  if (k <= a)
    cout << k << "\n";
  else {
    if (k <= a + b)
      cout << a << "\n";
    else
      cout << a + a + b - k << "\n";
  }
  return 0;
}
Problem p02682 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x)                                                                \
  {                                                                            \
    for (auto i : x) {                                                         \
      cout << i << " ";                                                        \
    }                                                                          \
    cout << endl;                                                              \
  }
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  vector<int> X;
  rep(i, A) X.push_back(1);
  rep(i, B) X.push_back(0);
  rep(i, C) X.push_back(-1);
  int ans = 0;
  rep(i, K) ans += X[i];
  cout << ans << '\n';
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x)                                                                \
  {                                                                            \
    for (auto i : x) {                                                         \
      cout << i << " ";                                                        \
    }                                                                          \
    cout << endl;                                                              \
  }
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  int ans = min(A, K);
  K -= min(A, K);
  if (K > 0) {
    K -= min(B, K);
  }
  if (K > 0) {
    ans -= K;
  }
  cout << ans << '\n';
  return 0;
}
Problem p02682 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main(void) {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  ll ans = 0;
  for (int i = 0; i < k; i++) {
    if (a != 0) {
      ans++;
      a--;
    } else if (b != 0) {
      b--;
    } else if (c != 0) {
      ans--;
      c--;
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main(void) {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  ll ans = 0;
  if (a > k) {
    cout << k << endl;
  } else if (a + b >= k) {
    cout << a << endl;
  } else
    cout << a - (k - a - b) << endl;
  return 0;
}
Problem p02682 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define For(i, n1, n2) for (int i = (int)(n1); i < (int)(n2); i++)

int main() {
  long long a, b, c, k;
  long long ans = 0;
  cin >> a >> b >> c >> k;
  Rep(i, k) {
    if (a > 0) {
      ans++;
      a--;
      continue;
    }
    if (b > 0) {
      b--;
      continue;
    }
    if (c > 0) {
      ans--;
      c--;
      continue;
    }
  }
  cout << ans;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define For(i, n1, n2) for (int i = (int)(n1); i < (int)(n2); i++)

int main() {
  int a, b, c, k;
  int ans = 0;
  cin >> a >> b >> c >> k;
  Rep(i, k) {
    if (a > 0) {
      ans++;
      a--;
      continue;
    }
    if (b > 0) {
      b--;
      continue;
    }
    if (c > 0) {
      ans--;
      c--;
      continue;
    }
  }
  cout << ans;
}
Problem p02682 (C++)

Buggy submission (status: 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>;

int main() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;

  ll s = 0;
  rep(i, k) {
    if (a > 0) {
      s += 1;
      a--;
    } else if (b > 0) {
      b--;
    } else {
      s -= 1;
      c--;
    }
  }
  cout << s << endl;
  return 0;
}

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

int main() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;

  ll s = 0;
  if (a >= k) {
    s = k;
  } else if (a + b >= k) {
    s = a;
  } else {
    s = a - (k - a - b);
  }
  cout << s << endl;
  return 0;
}
Problem p02682 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

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

int main(void) {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  ll ans = 0;
  rep(i, k) {
    if (a > 0) {
      ans++;
      a--;
    } else if (b > 0) {
      b--;
    } else {
      ans--;
      c--;
    }
  }
  cout << ans << endl;
  return 0;
}

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

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

int main(void) {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  ll ans = 0;
  if (a >= k)
    ans = k;
  else if (a + b >= k)
    ans = a;
  else
    ans = a - (k - a - b);
  cout << ans << endl;
  return 0;
}
Problem p02682 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;

  int sum = 0, i = 0;
  while (i < k) {
    if (a-- > 0)
      sum += 1;
    else if (b-- > 0)
      sum += 0;
    else if (c-- > 0)
      sum -= 1;
    else
      break;
    i++;
  }

  cout << sum;

  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;

int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;

  int sum = 0, i = k;

  if (a <= i) {
    sum += a;
    i -= a;
  } else {
    sum += i;
    i -= i;
  }

  if (b <= i) {
    i -= b;
  } else {
    i -= i;
  }

  if (c <= i) {
    sum -= c;
    i -= c;
  } else {
    sum -= i;
    i -= i;
  }

  cout << sum;

  return 0;
}
Problem p02682 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
const double PI = acos(-1);
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  vector<long long> num(a + b + c);
  rep(i, a) num.at(i) = 1;
  rep(i, b) num.at(a + i) = 0;
  rep(i, c) num.at(a + b + i) = -1;
  long long ans = 0;
  rep(i, k) ans += num.at(i);
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
const double PI = acos(-1);
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  if (k <= a)
    cout << k << endl;
  else if (k <= a + b)
    cout << a << endl;
  else
    cout << a - (k - a - b) << endl;
}
Problem p02682 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  long long A, B, C, K;
  cin >> A >> B >> C >> K;
  long long ans = 0;
  while (K > 0) {
    if (A > 0) {
      --K;
      --A;
      ++ans;
    } else if (A == 0 && B > 0) {
      --K;
      --B;
    } else if (B == 0 && C > 0) {
      --K;
      --C;
      --ans;
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  long long A, B, C, K;
  cin >> A >> B >> C >> K;
  long long ans = 0;
  if (A > K) {
    ans += K;
    K = 0;
  } else {
    ans += A;
    K -= A;
  }

  if (K > 0) {
    if (B > K) {
      K = 0;
    } else {
      K -= B;
    }
  }

  if (K > 0) {
    if (C > K) {
      ans -= K;
    } else {
      ans -= C;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02682 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  long A, B, C, K, Ans = 0, count = 1;

  cin >> A >> B >> C >> K;

  for (int i = 1; i <= A; i++) {
    if (count > K)
      break;
    Ans++;
    count++;
  }

  for (int i = 1; i <= B; i++) {
    if (count > K)
      break;
    count++;
  }

  for (int i = 1; i <= C; i++) {
    if (count > K)
      break;
    Ans--;
    count++;
  }

  cout << Ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long A, B, C, K, Ans = 0, count = 1;

  cin >> A >> B >> C >> K;

  for (int i = 1; i <= A; i++) {
    if (count > K)
      break;
    Ans++;
    count++;
  }

  count += B;

  for (int i = 1; i <= C; i++) {
    if (count > K)
      break;
    Ans--;
    count++;
  }

  cout << Ans << endl;

  return 0;
}
Problem p02682 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  ll A, B, C, K;
  cin >> A >> B >> C >> K;

  ll ans = 0;
  for (size_t i = 1; i <= K; i++) {
    if (A > 0) {
      ans += 1;
      A--;
    } else if (B > 0) {
      ans += 0;
      B--;
    } else if (C > 0) {
      ans += -1;
      C--;
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  ll A, B, C, K;
  cin >> A >> B >> C >> K;

  ll ans = 0;
  for (size_t i = 1; i <= K; i++) {
    if (A <= 0 && B <= 0 && C <= 0) {
      break;
    }

    if (A > 0) {
      ans += 1;
      A--;
    } else if (B > 0) {
      ans += 0;
      B--;
    } else if (C > 0) {
      ans += -1;
      C--;
    }
  }
  cout << ans << endl;
}
Problem p02682 (C++)

Buggy submission (status: Time Limit Exceeded):
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define l(i, a, b) for (auto i = a; i < b; i++)
#define lr(i, a, b) for (auto i = a; i >= b; i--)
#define ll long long
#define lli long long int
#define ld long double
#define vec vector<int>
#define mii map<ll, ll>
#define vl vector<long long>
#define se set<long long int>
#define pi pair<long long, long long>
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define all(v) v.begin(), v.end()
#define in(x) cin >> x
#define o(x) cout << x
#define SYNC                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
using namespace std;
int main() {
  SYNC ll a, b, c, k, sum = 0;
  in(a) >> b >> c >> k;
  l(i, 0, k) {
    if (a > 0) {
      sum += 1;
      a--;
    } else if (b > 0) {
      sum += 0;
      b--;
    } else
      sum -= 1;
  }
  o(sum);
}


Fixed submission:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define l(i, a, b) for (auto i = a; i < b; i++)
#define lr(i, a, b) for (auto i = a; i >= b; i--)
#define ll long long
#define lli long long int
#define ld long double
#define vec vector<int>
#define mii map<ll, ll>
#define vl vector<long long>
#define se set<long long int>
#define pi pair<long long, long long>
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define all(v) v.begin(), v.end()
#define in(x) cin >> x
#define o(x) cout << x
#define SYNC                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
using namespace std;
int main() {
  SYNC ll a, b, c, k, sum = 0;
  in(a) >> b >> c >> k;
  if (k == a + b + c) {
    sum += (a - c);
  } else if (k <= a + b && k >= a) {
    sum += a;
  } else if (k > a + b) {
    sum += a;
    k -= (a + b);
    sum -= k;
  } else if (k < a) {
    sum += k;
  }
  o(sum);
}
Problem p02682 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long A, B, C, K;
  cin >> A >> B >> C >> K;
  long long sum = 0;
  for (int i = 0; i < K; ++i) {

    if (A > 0) {
      sum++;
      A--;
    } else if (B > 0) {
      B--;
    } else if (C > 0) {
      sum--;
      C--;
    }
  }
  cout << sum << endl;
}


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

int main() {
  long long A, B, C, K;
  cin >> A >> B >> C >> K;
  long long sum = 0;
  if ((A + B) >= K && A < K) {
    sum = A;
  } else if (A >= K) {
    sum = K;
  } else {
    sum = A - (K - A - B);
  }
  cout << sum << endl;
}
Problem p02682 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int count = 0;
  rep(i, a + b + c) {
    rep(j, a) {
      if (k == 0) {
        break;
      }
      count++;
      k--;
    }
    rep(j, b) {
      if (k == 0) {
        break;
      }
      k--;
    }
    rep(j, c) {
      if (k == 0) {
        break;
      }
      count--;
      k--;
    }
  }
  cout << count << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int count = 0;
  rep(i, k) {
    rep(j, a) {
      if (k == 0) {
        break;
      }
      count++;
      k--;
    }
    rep(j, b) {
      if (k == 0) {
        break;
      }
      k--;
    }
    rep(j, c) {
      if (k == 0) {
        break;
      }
      count--;
      k--;
    }
  }
  cout << count << endl;
}
Problem p02682 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int ap, a0, am, k;
  cin >> ap >> a0 >> am >> k;
  long long ans = 0;
  for (int i = 0; i < k; i++) {
    if (ap > 0) {
      ap--;
      ans++;
    } else if (a0 > 0) {
      a0--;
    } else {
      am--;
      ans--;
    }
  }

  cout << ans << endl;
}

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

int main() {
  int ap, a0, am, k;
  cin >> ap >> a0 >> am >> k;
  if (a0 == 0 && am == 0) {
    cout << k << endl;
    return 0;
  }
  long long ans = 0;
  for (int i = 0; i < k; i++) {
    if (ap > 0) {
      ap--;
      ans++;
    } else if (a0 > 0) {
      a0--;
    } else {
      am--;
      ans--;
    }
  }

  cout << ans << endl;
}
Problem p02683 (C++)

Buggy submission (status: Runtime Error):
#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;
}

Fixed submission:
#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;
}
Problem p02683 (C++)

Buggy submission (status: 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(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;
  }
}

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(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;
  }
}
Problem p02683 (C++)

Buggy submission (status: Runtime Error):
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dunk(n) cout << n << endl
#define all(v) v.begin(), v.end()
typedef long long ll;

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<vector<int>> a(n, vector<int>(m));
  vector<int> c(m);
  rep(i, n) {
    cin >> c.at(i);
    rep(j, m) { cin >> a.at(i).at(j); }
  }

  int ans = 1001001001;

  rep(i, 1 << n) {
    int cost = 0;
    vector<int> d(m);
    rep(j, n) {
      if (i >> j & 1) {
        cost += c.at(j);
        rep(s, m) d.at(s) += a.at(j).at(s);
      }
    }
    bool ok = true;
    rep(j, m) if (d.at(j) < x) ok = false;
    if (ok)
      ans = min(ans, cost);
  }

  if (ans == 1001001001)
    dunk("-1");
  else
    dunk(ans);

  return 0;
}


Fixed submission:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dunk(n) cout << n << endl
#define all(v) v.begin(), v.end()
typedef long long ll;

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<vector<int>> a(n, vector<int>(m));
  vector<int> c(n);
  rep(i, n) {
    cin >> c.at(i);
    rep(j, m) { cin >> a.at(i).at(j); }
  }

  int ans = 1001001001;

  rep(i, 1 << n) {
    int cost = 0;
    vector<int> d(m);
    rep(j, n) {
      if (i >> j & 1) {
        cost += c.at(j);
        rep(s, m) d.at(s) += a.at(j).at(s);
      }
    }
    bool ok = true;
    rep(j, m) if (d.at(j) < x) ok = false;
    if (ok)
      ans = min(ans, cost);
  }

  if (ans == 1001001001)
    dunk("-1");
  else
    dunk(ans);

  return 0;
}
Problem p02683 (C++)

Buggy submission (status: 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>(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;
}

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>(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;
}
Problem p02683 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, m, x, a, c, ans;
  cin >> n >> m >> x;
  vector<int> C;
  vector<vector<int>> A;
  for (int i = 0; i < n; i++) {
    cin >> c;
    C.push_back(c);
    for (int j = 0; j < m; j++) {
      cin >> a;
      A[i][j] = a;
    }
  }
  ans = 10000000;
  int p, ok;
  for (int i = 0; i < (1 << n); i++) {
    p = 0;
    ok = 0;
    vector<int> skill(m);
    for (int j = 0; j < n; j++) {
      if (i & (1 << j)) {
        p += C[j];
        for (int k = 0; k < m; k++) {
          skill[k] += A[j][k];
        }
      }
    }
    for (int l = 0; l < m; l++) {
      if (skill[l] < x) {
        ok = -1;
        break;
      }
    }
    if (ok == 0) {
      if (p < ans) {
        ans = p;
      }
    }
  }
  if (ans == 10000000) {
    ans = -1;
    cout << ans;
  } else {
    cout << ans;
  }
}


Fixed submission:
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, m, x, a, c, ans;
  cin >> n >> m >> x;
  vector<int> C;
  vector<vector<int>> A(n, vector<int>(m));
  for (int i = 0; i < n; i++) {
    cin >> c;
    C.push_back(c);
    for (int j = 0; j < m; j++) {
      cin >> a;
      A[i][j] = a;
    }
  }
  ans = 10000000;
  int p, ok;
  for (int i = 0; i < (1 << n); i++) {
    p = 0;
    ok = 0;
    vector<int> skill(m);
    for (int j = 0; j < n; j++) {
      if (i & (1 << j)) {
        p += C[j];
        for (int k = 0; k < m; k++) {
          skill[k] += A[j][k];
        }
      }
    }
    for (int l = 0; l < m; l++) {
      if (skill[l] < x) {
        ok = -1;
        break;
      }
    }
    if (ok == 0) {
      if (p < ans) {
        ans = p;
      }
    }
  }
  if (ans == 10000000) {
    ans = -1;
    cout << ans;
  } else {
    cout << ans;
  }
}
Problem p02683 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <vector>
using namespace std;

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

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

  int ans = INF;
  // 全ビット探索
  for (int s = 0; s < n; 1 << n) {
    // cost 今までの本の総額
    // d 理解度
    int cost = 0;
    vector<int> d(m);

    for (int i = 0; i < n; i++) {
      // i番目の本を購入する場合
      if (s >> i & 1) {
        cost += c[i];
        for (int j = 0; j < m; j++)
          d[j] += a[i][j];
      }
    }
    bool ok = true;
    // アルゴリズムj番目の理解度がx未満なら判定を
    // falseにする
    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 0;
}

Fixed submission:
#include <iostream>
#include <vector>
using namespace std;

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

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

  int ans = INF;
  // 全ビット探索
  for (int s = 0; s < 1 << n; s++) {
    // cost 今までの本の総額
    // d 理解度
    int cost = 0;
    vector<int> d(m);

    for (int i = 0; i < n; i++) {
      // i番目の本を購入する場合
      if (s >> i & 1) {
        cost += c[i];
        for (int j = 0; j < m; j++)
          d[j] += a[i][j];
      }
    }
    bool ok = true;
    // アルゴリズムj番目の理解度がx未満なら判定を
    // falseにする
    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 0;
}
Problem p02683 (Python)

Buggy submission (status: Runtime Error):
n, m, x = map(int, input().split())
c = [0] * n
a = [0] * n
for i in range(n):
    xs = list(map(int, input().split()))
    c[i] = xs[0]
    a[i] = xs[1:]
ans = 10**9
for i in range(2**n):
    csum = 0
    asum = [0] * n
    for j in range(n):
        if (i >> j) & 1:
            csum += c[j]
            for k in range(m):
                asum[k] += a[j][k]
    if len(list(filter(lambda v: v >= x, asum))) == m:
        ans = min(ans, csum)
print(-1 if ans == 10**9 else ans)


Fixed submission:
n, m, x = map(int, input().split())
c = [0] * n
a = [0] * n
for i in range(n):
    xs = list(map(int, input().split()))
    c[i] = xs[0]
    a[i] = xs[1:]
ans = 10**9
for i in range(2**n):
    csum = 0
    asum = [0] * m
    for j in range(n):
        if (i >> j) & 1:
            csum += c[j]
            for k in range(m):
                asum[k] += a[j][k]
    if len(list(filter(lambda v: v >= x, asum))) == m:
        ans = min(ans, csum)
print(-1 if ans == 10**9 else ans)
Problem p02683 (C++)

Buggy submission (status: Runtime Error):
#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>;

const int INF = 1001001001;

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  int a[n][n];
  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;
}


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

const int INF = 1001001001;

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  int a[n][m];
  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 (status: Runtime Error):
#include <bits/stdc++.h>
#define repr(i, from, to) for (int(i) = (from); (i) < (to); (i)++)
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
// const bool debug=true;
const bool debug = false;
#define DEBUG if (debug == true)
#define all(x) begin((x)), end((x))
#define vprint(x)                                                              \
  for (auto a : (x))                                                           \
    cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
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(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m, x;
  cin >> n >> m >> x;
  vector<vector<ll>> mat(n, vector<ll>(n));
  vector<ll> c(n);
  rep(i, n) {
    cin >> c[i];
    rep(j, m) { cin >> mat[i][j]; }
  }
  ll res = 1LL << 60;
  rep(i, 1 << n) {
    vector<ll> val(m, 0);
    ll money = 0;
    rep(j, n) {
      if (i >> j & 1) {
        money += c[j];
        rep(k, m) { val[k] += mat[j][k]; }
      }
    }
    // cout << i << endl;
    // rep(j,n) {
    //     cout << val[i] << " ";
    // }
    // cout << endl;
    // cout << "money " << money << endl;
    bool flg = true;
    rep(j, m) { flg &= val[j] >= x; }
    if (flg) {
      chmin(res, money);
    }
  }
  cout << ((res == (1LL << 60)) ? -1 : res) << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define repr(i, from, to) for (int(i) = (from); (i) < (to); (i)++)
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
// const bool debug=true;
const bool debug = false;
#define DEBUG if (debug == true)
#define all(x) begin((x)), end((x))
#define vprint(x)                                                              \
  for (auto a : (x))                                                           \
    cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
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(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m, x;
  cin >> n >> m >> x;
  vector<vector<ll>> mat(n, vector<ll>(m));
  vector<ll> c(n);
  rep(i, n) {
    cin >> c[i];
    rep(j, m) { cin >> mat[i][j]; }
  }
  ll res = 1LL << 60;
  rep(i, 1 << n) {
    vector<ll> val(m, 0);
    ll money = 0;
    rep(j, n) {
      if (i >> j & 1) {
        money += c[j];
        rep(k, m) { val[k] += mat[j][k]; }
      }
    }
    // cout << i << endl;
    // rep(j,n) {
    //     cout << val[i] << " ";
    // }
    // cout << endl;
    // cout << "money " << money << endl;
    bool flg = true;
    rep(j, m) { flg &= val[j] >= x; }
    if (flg) {
      chmin(res, money);
    }
  }
  cout << ((res == (1LL << 60)) ? -1 : res) << endl;
  return 0;
}
Problem p02683 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int optimal = INT_MAX;
void call(vector<vector<int>> &v, int n, int m, int temp, int k, vector<int> tt,
          int var, int cost[]) {
  if (n == temp) {
    int flag = 1;
    for (int i = 0; i < m; i++) {
      if (tt[i] < k) {
        flag = 0;
        break;
      }
    }

    if (flag) {
      optimal = min(optimal, var);
    }
    return;
  }

  call(v, n, m, temp + 1, k, tt, var, cost);
  for (int i = 0; i < m; i++) {
    tt[i] += v[temp][i];
  }
  call(v, n, m, temp + 1, k, tt, var + cost[temp], cost);
}
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
#endif
  int n, m, k;
  cin >> n >> m >> k;
  vector<vector<int>> v(n, vector<int>(m));
  int cost[m];
  for (int i = 0; i < n; i++) {
    cin >> cost[i];
    for (int j = 0; j < m; j++) {
      cin >> v[i][j];
    }
  }
  vector<int> tt(m, 0);
  int var = 0;
  int temp = 0;
  call(v, n, m, temp, k, tt, var, cost);
  if (optimal == INT_MAX) {
    cout << -1 << endl;
  } else {
    cout << optimal << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int optimal = INT_MAX;
void call(vector<vector<int>> &v, int n, int m, int temp, int k, vector<int> tt,
          int var, int cost[]) {
  if (n == temp) {
    int flag = 1;
    for (int i = 0; i < m; i++) {
      if (tt[i] < k) {
        flag = 0;
        break;
      }
    }

    if (flag) {
      optimal = min(optimal, var);
    }
    return;
  }

  call(v, n, m, temp + 1, k, tt, var, cost);
  for (int i = 0; i < m; i++) {
    tt[i] += v[temp][i];
  }
  call(v, n, m, temp + 1, k, tt, var + cost[temp], cost);
}
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
#endif
  int n, m, k;
  cin >> n >> m >> k;
  vector<vector<int>> v(n, vector<int>(m));
  int cost[n];
  for (int i = 0; i < n; i++) {
    cin >> cost[i];
    for (int j = 0; j < m; j++) {
      cin >> v[i][j];
    }
  }
  vector<int> tt(m, 0);
  int var = 0;
  int temp = 0;
  call(v, n, m, temp, k, tt, var, cost);
  if (optimal == INT_MAX) {
    cout << -1 << endl;
  } else {
    cout << optimal << endl;
  }
  return 0;
}
Problem p02683 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vi c(n);
  vvi a(n, vi(m));
  bitset<12> bb;
  for (int ix = 0; ix < n; ix++) {
    cin >> c.at(ix);
    for (int ix2 = 0; ix2 < m; ix2++) {
      cin >> a.at(ix).at(ix2);
    }
  }
  int64_t purchase = 1000000007;
  for (int ix = 0; ix < (1 << n); ix++) {
    bb = ix;
    bool can = true;
    int64_t tmp = 0;
    vi test(n, 0);
    for (int ix2 = 0; ix2 < n; ix2++) {
      if (bb.test(ix2)) {
        tmp += c.at(ix2);
        for (int ix3 = 0; ix3 < m; ix3++) {
          test.at(ix3) += a.at(ix2).at(ix3);
        }
      }
    }
    for (int ix4 = 0; ix4 < m; ix4++)
      if (test.at(ix4) < x)
        can = false;
    if (can)
      purchase = min(purchase, tmp);
  }
  cout << (purchase != 1000000007 ? purchase : (int64_t)-1) << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vi c(n);
  vvi a(n, vi(m));
  bitset<12> bb;
  for (int ix = 0; ix < n; ix++) {
    cin >> c.at(ix);
    for (int ix2 = 0; ix2 < m; ix2++) {
      cin >> a.at(ix).at(ix2);
    }
  }
  int64_t purchase = 1000000007;
  for (int ix = 0; ix < (1 << n); ix++) {
    bb = ix;
    bool can = true;
    int64_t tmp = 0;
    vi test(m, 0);
    for (int ix2 = 0; ix2 < n; ix2++) {
      if (bb.test(ix2)) {
        tmp += c.at(ix2);
        for (int ix3 = 0; ix3 < m; ix3++) {
          test.at(ix3) += a.at(ix2).at(ix3);
        }
      }
    }
    for (int ix4 = 0; ix4 < m; ix4++)
      if (test.at(ix4) < x)
        can = false;
    if (can)
      purchase = min(purchase, tmp);
  }
  cout << (purchase != 1000000007 ? purchase : (int64_t)-1) << endl;
}
Problem p02683 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>

using namespace std;

int n, m, x;
int c[15];
int res = 1e9;
int a[15][15];
vector<int> ans;

void f(int i) {
  //  cout << i << endl;
  if (i == n) {
    vector<int> A(n, 0);
    int sum = 0;
    for (int j = 0; j < ans.size(); j++) {
      sum += c[ans[j]];
      for (int k = 0; k < m; k++) {
        A[k] += a[ans[j]][k];
      }
    }

    for (int j = 0; j < m; j++) {
      if (A[j] < x) {
        return;
      }
    }

    res = min(res, sum);
    return;
  }

  ans.push_back(i);
  f(i + 1);
  ans.pop_back();
  f(i + 1);

  return;
}

int main() {
  cin >> n >> m >> x;

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

  // cout << "Iji2" << endl;

  f(0);

  if (res == 1e9) {
    cout << -1 << endl;
  } else
    cout << res << endl;
}

Fixed submission:
#include <iostream>
#include <vector>

using namespace std;

int n, m, x;
int c[15];
int res = 1e9;
int a[15][15];
vector<int> ans;

void f(int i) {
  //  cout << i << endl;
  if (i == n) {
    vector<int> A(m, 0);
    int sum = 0;
    for (int j = 0; j < ans.size(); j++) {
      sum += c[ans[j]];
      for (int k = 0; k < m; k++) {
        A[k] += a[ans[j]][k];
      }
    }

    for (int j = 0; j < m; j++) {
      if (A[j] < x) {
        return;
      }
    }

    res = min(res, sum);
    return;
  }

  ans.push_back(i);
  f(i + 1);
  ans.pop_back();
  f(i + 1);

  return;
}

int main() {
  cin >> n >> m >> x;

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

  // cout << "Iji2" << endl;

  f(0);

  if (res == 1e9) {
    cout << -1 << endl;
  } else
    cout << res << endl;
}
Problem p02683 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int INF = 1000000007;

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m, 0));
  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 = 1; bit << (1 << n); bit++) {
    vector<int> u(m, 0);
    int sum = 0;
    for (int i = 0; i < n; i++) {
      if ((bit >> i) & 1) {
        sum += c[i];
        for (int j = 0; j < m; j++)
          u[j] += a[i][j];
      }
    }
    bool f = true;
    for (int j = 0; j < m; j++) {
      if (u[j] < x)
        f = false;
    }
    if (f)
      ans = min(sum, ans);
  }
  if (ans == INF) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int INF = 1000000007;

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m, 0));
  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 = 1; bit < (1 << n); bit++) {
    vector<int> u(m, 0);
    int sum = 0;
    for (int i = 0; i < n; i++) {
      if ((bit >> i) & 1) {
        sum += c[i];
        for (int j = 0; j < m; j++)
          u[j] += a[i][j];
      }
    }
    bool f = true;
    for (int j = 0; j < m; j++) {
      if (u[j] < x)
        f = false;
    }
    if (f)
      ans = min(sum, ans);
  }
  if (ans == INF) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}
Problem p02683 (C++)

Buggy submission (status: 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;
}

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