Problem p03290 (C++)

Buggy submission (status: Time Limit Exceeded):
#include "bits/stdc++.h"
#include <iostream>
using namespace std;
#define print(x) cout << x << endl;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define REP(i, a) for (int i = 0; i < a; i++)
#define debug int debug = 0;
#define RREP(i, a) for (int i = a - 1; i >= 0; i--)
#define rrep(i, a, b) for (int i = a - 1; i >= b; i--)
#define printall(n, array)                                                     \
  {                                                                            \
    for (int i = 0; i < n; i++) {                                              \
      cout << array[i] << " ";                                                 \
    }                                                                          \
    cout << endl;                                                              \
  }
#define U() cout << endl;
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<int, Pi> V;
typedef vector<ll> VE;
const ll mod = 1e9 + 7; // 10^9+7

int main() {
  ll d, g;
  ll p[102], c[102];
  ll used[102] = {};
  cin >> d >> g;
  REP(i, d) { cin >> p[i] >> c[i]; }
  ll ans = mod;
  REP(mask, mask < (1 << d)) {
    ll s = 0, num = 0, rest_max = -1;
    REP(i, d) {
      if (mask >> i & 1) {
        s += 100 * p[i] * (i + 1) + c[i];
        num += p[i];
      } else {
        rest_max = i;
      }
    }
    if (s < g) {
      ll s1 = 100 * (rest_max + 1);
      ll need = (g - s + s1 - 1) / s1;
      if (need >= p[rest_max]) {
        continue;
      }
      num += need;
    }
    ans = min(ans, num);
  }
  print(ans);
}


Fixed submission:
#include "bits/stdc++.h"
#include <iostream>
using namespace std;
#define print(x) cout << x << endl;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define REP(i, a) for (int i = 0; i < a; i++)
#define debug int debug = 0;
#define RREP(i, a) for (int i = a - 1; i >= 0; i--)
#define rrep(i, a, b) for (int i = a - 1; i >= b; i--)
#define printall(n, array)                                                     \
  {                                                                            \
    for (int i = 0; i < n; i++) {                                              \
      cout << array[i] << " ";                                                 \
    }                                                                          \
    cout << endl;                                                              \
  }
#define U() cout << endl;
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<int, Pi> V;
typedef vector<ll> VE;
const ll mod = 1e9 + 7; // 10^9+7

int main() {
  ll d, g;
  ll p[102], c[102];
  ll used[102] = {};
  cin >> d >> g;
  REP(i, d) { cin >> p[i] >> c[i]; }
  ll ans = mod;
  REP(mask, (1 << d)) {
    ll s = 0, num = 0, rest_max = -1;
    REP(i, d) {
      if (mask >> i & 1) {
        s += 100 * p[i] * (i + 1) + c[i];
        num += p[i];
      } else {
        rest_max = i;
      }
    }
    if (s < g) {
      ll s1 = 100 * (rest_max + 1);
      ll need = (g - s + s1 - 1) / s1;
      if (need >= p[rest_max]) {
        continue;
      }
      num += need;
    }
    ans = min(ans, num);
  }
  print(ans);
}