Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef map<int, int> mi;
typedef set<int> si;
#define VV(T) vector<vector<T>>
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl

#define rep(i, n) REP(i, 0, n)                   // 0, 1, ..., n-1
#define REP(i, x, n) for (int i = x; i < n; i++) // x, x + 1, ..., n-1
#define FOREACH(x, a) for (auto &(x) : (a))

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define pb push_back
#define pu push
#define mp make_pair
#define fi first
#define sc second

#define COUT(x) cout << (x) << endl
#define VECCIN(x)                                                              \
  for (auto &youso_ : (x))                                                     \
  cin >> youso_
#define VECCOUT(x)                                                             \
  for (auto &youso_ : (x))                                                     \
    cout << youso_ << " ";                                                     \
  cout << endl

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() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int R, G, B, N;
  cin >> R >> G >> B >> N;
  int ans = 0;
  rep(r, N + 1) {
    rep(g, N + 1) {
      rep(b, N + 1) {
        if (r * R + g * G + b * B == N) {
          ans++;
        }
        if (r * R + g * G + b * B > N)
          break;
      }
    }
  }
  COUT(ans);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef map<int, int> mi;
typedef set<int> si;
#define VV(T) vector<vector<T>>
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl

#define rep(i, n) REP(i, 0, n)                   // 0, 1, ..., n-1
#define REP(i, x, n) for (int i = x; i < n; i++) // x, x + 1, ..., n-1
#define FOREACH(x, a) for (auto &(x) : (a))

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define pb push_back
#define pu push
#define mp make_pair
#define fi first
#define sc second

#define COUT(x) cout << (x) << endl
#define VECCIN(x)                                                              \
  for (auto &youso_ : (x))                                                     \
  cin >> youso_
#define VECCOUT(x)                                                             \
  for (auto &youso_ : (x))                                                     \
    cout << youso_ << " ";                                                     \
  cout << endl

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() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int R, G, B, N;
  cin >> R >> G >> B >> N;
  int ans = 0;
  rep(r, N + 1) {
    rep(g, N + 1) {
      int b = (N - (R * r + G * g)) / B;
      if (N - (R * r + G * g + b * B) == 0 && b >= 0) {
        ans++;
      }
    }
  }
  COUT(ans);
}