Problem p03290 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;

#define FOR(i, n, m) for (ll i = (ll)(m); i < (ll)(n); ++i)
#define REP(i, n) FOR(i, n, 0)
#define IREP(i, n) for (ll i = (ll)(n); i >= 0; --i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

pll pc[15];

vector<vector<int>> s;
int D;
bool c = false;
ll sum = 0;
ll sumI = 0;
ll n;

void dfs(vector<int> v) {
  if (v.size() == D) {
    s.push_back(v);
    return;
  }
  IREP(i, D - 1) {
    c = false;
    REP(j, v.size()) {

      if (v[j] == i) {
        c = true;
        break;
      }
    }
    if (c)
      continue;

    v.push_back(i);
    dfs(v);
    v.pop_back();
  }
  return;
}

int main() {

  ll G;
  cin >> D >> G;
  vector<ll> v(D); //! 全部解いたら何点？
  ll t = 1;
  REP(i, D) {
    t *= (i + 1);
    cin >> pc[i].first >> pc[i].second;
    v[i] = (i + 1) * pc[i].first * 100 + pc[i].second;
  }

  vector<int> tmp;
  dfs(tmp);

  ll ans = INF;

  REP(i, s.size()) {
    sum = 0;
    sumI = 0;
    REP(j, D) {
      int index = s[i][j];
      ll n = (G - sum + 100 * (1 + index) - 1) / (100 * (1 + index));
      if (n < pc[index].first) {
        sum += 100 * (1 + index) * n;
        sumI += n;
      } else {
        sum += v[index];
        sumI += pc[index].first;
      }
      if (sum >= G) {
        ans = std::min(ans, sumI);
        break;
      }
      if (ans <= sumI) {
        break;
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;

#define FOR(i, n, m) for (ll i = (ll)(m); i < (ll)(n); ++i)
#define REP(i, n) FOR(i, n, 0)
#define IREP(i, n) for (ll i = (ll)(n); i >= 0; --i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

pll pc[15];

vector<vector<int>> s;
int D;
bool c = false;
ll sum = 0;
ll sumI = 0;
ll n;

inline void dfs(vector<int> v) {
  if (v.size() == D) {
    s.push_back(v);
    return;
  }
  IREP(i, D - 1) {
    c = false;
    REP(j, v.size()) {

      if (v[j] == i) {
        c = true;
        break;
      }
    }
    if (c)
      continue;

    v.push_back(i);
    dfs(v);
    v.pop_back();
  }
  return;
}

int main() {

  ll G;
  cin >> D >> G;
  vector<ll> v(D); //! 全部解いたら何点？
  ll t = 1;
  REP(i, D) {
    t *= (i + 1);
    cin >> pc[i].first >> pc[i].second;
    v[i] = (i + 1) * pc[i].first * 100 + pc[i].second;
  }

  vector<int> tmp;
  dfs(tmp);

  ll ans = INF;

  REP(i, s.size()) {
    sum = 0;
    sumI = 0;
    REP(j, D) {
      int index = s[i][j];
      ll n = (G - sum + 100 * (1 + index) - 1) / (100 * (1 + index));
      if (n < pc[index].first) {
        sum += 100 * (1 + index) * n;
        sumI += n;
      } else {
        sum += v[index];
        sumI += pc[index].first;
      }
      if (sum >= G) {
        ans = std::min(ans, sumI);
        break;
      }
      if (ans <= sumI) {
        break;
      }
    }
  }

  cout << ans << endl;

  return 0;
}