Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = (int)(a); i >= (int)(b); --i)
#define fore(i, a) for (auto &i : a)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define isin(i, a, b) ((a) <= (i) && (i) < (b))
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using unit = unsigned;
using ull = unsigned long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vp = vector<P>;
void _main();
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  _main();
}
template <class T> void YES(T condition) {
  if (condition)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
template <class T> void Yes(T condition) {
  if (condition)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
template <class T> void POSS(T condition) {
  if (condition)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
}
template <class T> void Poss(T condition) {
  if (condition)
    cout << "Possible" << endl;
  else
    cout << "Impossible" << endl;
}
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> T gcd(T a, T b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
constexpr double eps = 1e-10;
constexpr int inf = INT_MAX / 2;
constexpr ll infl = 1LL << 60;

void _main() {
  int R, G, B, N;
  cin >> R >> G >> B >> N;

  int ans = 0;
  for (int i = 0; i <= N; i += R) {
    for (int j = 0, je = N - i; j <= je; j += G) {
      for (int k = 0, ke = N - i - j; k <= ke; k += B) {
        if (i + j + k == N)
          ++ans;
      }
    }
  }

  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = (int)(a); i >= (int)(b); --i)
#define fore(i, a) for (auto &i : a)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define isin(i, a, b) ((a) <= (i) && (i) < (b))
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using unit = unsigned;
using ull = unsigned long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vp = vector<P>;
void _main();
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  _main();
}
template <class T> void YES(T condition) {
  if (condition)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
template <class T> void Yes(T condition) {
  if (condition)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
template <class T> void POSS(T condition) {
  if (condition)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
}
template <class T> void Poss(T condition) {
  if (condition)
    cout << "Possible" << endl;
  else
    cout << "Impossible" << endl;
}
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> T gcd(T a, T b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
constexpr double eps = 1e-10;
constexpr int inf = INT_MAX / 2;
constexpr ll infl = 1LL << 60;

void _main() {
  int R, G, B, N;
  cin >> R >> G >> B >> N;

  int ans = 0;
  for (int i = 0; i <= N; i += R) {
    for (int j = 0, je = N - i; j <= je; j += G) {
      if ((N - i - j) % B == 0)
        ++ans;
    }
  }

  cout << ans << endl;
}