Problem p03290 (C++)

Buggy submission (status: Time Limit Exceeded):
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using std::abs;
using std::bitset;
using std::cerr;
using std::cin;
using std::cout;
using std::map;
using std::max;
using std::min;
using std::pair;
using std::set;
using std::string;
using std::swap;
using std::unordered_map;
using std::unordered_set;
using std::vector;
using ll = long long;
using uint = unsigned int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using ull = unsigned long long;
using ld = long double;
using vci = vector<int>;
using vcl = vector<ll>;
template <typename T> void _dbg(const char *_s, T _h) {
  cerr << _s << " = " << _h << "\n";
}
template <typename T, typename... Ts>
void _dbg(const char *_s, T _h, Ts... _t) {
  int _b = 0;
  while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
    cerr << *_s++;
  cerr << " = " << _h << ",";
  _dbg(_s + 1, _t...);
}
#define f first
#define s second
#define pb emplace_back
struct init {
  init() {
    cin.tie(0);
    std::iostream::sync_with_stdio(0);
    cout << std::fixed << std::setprecision(10);
    cerr << std::fixed << std::setprecision(5);
  }
  ~init() {
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
    cerr << "Time elapsed: " << (double)clock() / CLOCKS_PER_SEC << "s.\n";
#else
#define dbg(...)
#endif
  }
} init;
ll p[11], c[11];
int32_t main() {

  ll n, g;
  cin >> n >> g;
  for (int i = 1; i <= n; ++i)
    cin >> p[i] >> c[i];
  vector<int> v(n);
  iota(v.begin(), v.end(), 1);
  int ans = 123456789;
  do {
    ll cur = g;
    int pot = 0;
    for (int i : v) {
      int w = p[i];
      while (w && cur > 0) {
        pot++;
        w--;
        cur -= i * 100;
      }
      if (!w)
        cur -= c[i];
      if (cur < 0) {
        break;
      }
    }
    ans = min(ans, pot);
  } while (next_permutation(v.begin(), v.end()));
  cout << ans << '\n';

  return 0;
}


Fixed submission:
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using std::abs;
using std::bitset;
using std::cerr;
using std::cin;
using std::cout;
using std::map;
using std::max;
using std::min;
using std::pair;
using std::set;
using std::string;
using std::swap;
using std::unordered_map;
using std::unordered_set;
using std::vector;
using ll = long long;
using uint = unsigned int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using ull = unsigned long long;
using ld = long double;
using vci = vector<int>;
using vcl = vector<ll>;
template <typename T> void _dbg(const char *_s, T _h) {
  cerr << _s << " = " << _h << "\n";
}
template <typename T, typename... Ts>
void _dbg(const char *_s, T _h, Ts... _t) {
  int _b = 0;
  while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
    cerr << *_s++;
  cerr << " = " << _h << ",";
  _dbg(_s + 1, _t...);
}
#define f first
#define s second
#define pb emplace_back
struct init {
  init() {
    cin.tie(0);
    std::iostream::sync_with_stdio(0);
    cout << std::fixed << std::setprecision(10);
    cerr << std::fixed << std::setprecision(5);
  }
  ~init() {
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
    cerr << "Time elapsed: " << (double)clock() / CLOCKS_PER_SEC << "s.\n";
#else
#define dbg(...)
#endif
  }
} init;
ll p[11], c[11];
int32_t main() {

  ll n, g;
  cin >> n >> g;
  for (int i = 1; i <= n; ++i)
    cin >> p[i] >> c[i];
  vector<int> v(n);
  iota(v.begin(), v.end(), 1);
  int ans = 123456789;
  do {
    ll cur = g;
    int pot = 0;
    for (int i : v) {
      int w = p[i];
      while (w && cur > 0) {
        pot++;
        w--;
        cur -= i * 100;
      }
      if (!w)
        cur -= c[i];
      if (cur < 0) {
        break;
      }
    }
    ans = min(ans, pot);
  } while (next_permutation(v.begin(), v.end()));
  cout << ans << '\n';

  return 0;
}