Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define initdp(a, b)                                                           \
  for (int i = 0; i <= a; i++)                                                 \
    for (int j = 0; j <= b; j++)                                               \
      dp[i][j] = -1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
#define ll long long
#define pll pair<ll, ll>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n - 1; i >= 0; i--)
#define waste                                                                  \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)
#define inf 1e9 + 1
#define inf1 1e18 + 1
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l, r) l + (r - l) / 2
void mad(ll &a, ll b) {
  a = (a + b) % mod;
  if (a < 0)
    a += mod;
}
using namespace std;

void solve() {
  int r, g, b, n;
  cin >> r >> g >> b >> n;
  int x = n / r;
  int y = n / g;
  int res = 0;
  int z = n / b;
  for (int i = 0; i <= x; i++) {
    int n1 = r * i;
    for (int j = 0; j <= y; j++) {
      int n2 = g * j;
      if (n1 + n2 > n)
        break;
      for (int k = 0; k <= z; k++) {
        int n3 = b * k;
        if (n1 + n2 + n3 > n)
          break;
        if (n1 + n2 + n3 == n)
          res++;
      }
    }
  }
  cout << res;
}
int main() {
  waste;
  int t;
  // cin>>t;
  t = 1;
  while (t--) {
    solve();
  }
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define initdp(a, b)                                                           \
  for (int i = 0; i <= a; i++)                                                 \
    for (int j = 0; j <= b; j++)                                               \
      dp[i][j] = -1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
#define ll long long
#define pll pair<ll, ll>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n - 1; i >= 0; i--)
#define waste                                                                  \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)
#define inf 1e9 + 1
#define inf1 1e18 + 1
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l, r) l + (r - l) / 2
void mad(ll &a, ll b) {
  a = (a + b) % mod;
  if (a < 0)
    a += mod;
}
using namespace std;

void solve() {
  int r, g, b, n;
  cin >> r >> g >> b >> n;
  int x = n / r;
  int y = n / g;
  int res = 0;
  int z = n / b;
  for (int i = 0; i <= x; i++) {
    int n1 = r * i;
    for (int j = 0; j <= y; j++) {
      int n2 = g * j;
      if (n1 + n2 > n)
        break;
      int t = n - n1 - n2;
      if (t % b == 0)
        res++;
    }
  }
  cout << res;
}
int main() {
  waste;
  int t;
  // cin>>t;
  t = 1;
  while (t--) {
    solve();
  }
}