Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
/*
    �����悭�ǂ����I
    �_���I�ɍl���悤�I
    �T���v�����m�F���悤!
    ��΂ɒ��߂�ȁI
    �H�v������I
    �z��͏������߂ɂƂ��Ă���

    Twitter�͏I���܂Ń��O�A�E�g�I
    �i�ԈႦ�ĉ�@���c�C�[�g���Ă͂����Ȃ�����j

*/
// include
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
// namespace
using namespace std;
// �J��Ԃ�
#define REP(i, m, n) for (int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)
// �C�e���[�^
#define all_range(C) begin(C), end(C)
// �ȗ���
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<ll, int> pli;
typedef pair<string, int> pst;

const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
// �ő�ŏ�
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
  if (a > b)
    a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
  if (a < b)
    a = b;
}

// �֐�

// �ő���񐔂����߂�
ll my_gcd(ll x, ll y) {
  ll r;

  while (y != 0) {
    r = x % y;
    x = y;
    y = r;
  }

  return x;
}

// �ŏ����񐔂����߂�
ll my_lcm(ll x, ll y) { return (x * y) / my_gcd(x, y); }

// x��y������߂� ���Q�l�F10^18��܂�
ll my_pow(ll x, ll y) {
  ll sum = 1;

  while (y > 0) {
    sum *= x;
    --y;
  }

  return sum;
}

/*�l���������X�y�[�X


*/

// main.cpp----------------------------

int main() {
  int r, g, b, n;
  cin >> r >> g >> b >> n;

  int cnt = 0;
  for (int i = 0; i <= n / r; ++i) {
    for (int j = 0; j <= n / g; ++j) {
      for (int k = 0; k <= n / b; ++k) {
        if (i * r + j * g + k * b == n) {
          ++cnt;
        }
      }
    }
  }

  cout << cnt << endl;

  return 0;
}


Fixed submission:
/*
    �����悭�ǂ����I
    �_���I�ɍl���悤�I
    �T���v�����m�F���悤!
    ��΂ɒ��߂�ȁI
    �H�v������I
    �z��͏������߂ɂƂ��Ă���

    Twitter�͏I���܂Ń��O�A�E�g�I
    �i�ԈႦ�ĉ�@���c�C�[�g���Ă͂����Ȃ�����j

*/
// include
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
// namespace
using namespace std;
// �J��Ԃ�
#define REP(i, m, n) for (int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)
// �C�e���[�^
#define all_range(C) begin(C), end(C)
// �ȗ���
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<ll, int> pli;
typedef pair<string, int> pst;

const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
// �ő�ŏ�
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
  if (a > b)
    a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
  if (a < b)
    a = b;
}

// �֐�

// �ő���񐔂����߂�
ll my_gcd(ll x, ll y) {
  ll r;

  while (y != 0) {
    r = x % y;
    x = y;
    y = r;
  }

  return x;
}

// �ŏ����񐔂����߂�
ll my_lcm(ll x, ll y) { return (x * y) / my_gcd(x, y); }

// x��y������߂� ���Q�l�F10^18��܂�
ll my_pow(ll x, ll y) {
  ll sum = 1;

  while (y > 0) {
    sum *= x;
    --y;
  }

  return sum;
}

/*�l���������X�y�[�X


*/

// main.cpp----------------------------

int main() {
  int r, g, b, n;
  cin >> r >> g >> b >> n;

  int cnt = 0;
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j <= n; ++j) {
      int k = n - (i * r + j * g);
      if (k % b == 0 && k >= 0)
        ++cnt;
    }
  }

  cout << cnt << endl;

  return 0;
}