Problem p03835 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;

#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

#define vint(v, n)                                                             \
  vector<int> v(n);                                                            \
  REP(i, n) cin >> v[i];
#define vlint(v, n)                                                            \
  vector<ll int> v(n);                                                         \
  REP(i, n) cin >> v[i];
#define vdouble(v, n)                                                          \
  vector<double> v(n);                                                         \
  REP(i, n) cin >> v[i];
#define vvdoube(v, n1, n2)                                                     \
  vector<vector<double>> v(n1, vector<double>(n2, 0));                         \
  REP(i, n1) REP(j, n1) cin >> v[i][j];
#define string(x)                                                              \
  string x;                                                                    \
  cin >> x;
#define vstring(v, n)                                                          \
  vector<string> v(n);                                                         \
  REP(i, n) {                                                                  \
    string a;                                                                  \
    std::cin >> a;                                                             \
    v.push_back(a);                                                            \
  }

#define all(v) (v).begin(), (v).end()
#define rall(v) (v).begin(), (v).end(), std::greater<int>()

static const string
    abet("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
static const long long int MOD = 1000000007;
static const double PI = 3.1415926535897932;
static const int INF = 0x3f3f3f3f;
static const int INFTY = (1 << 29);
static const long long LINFTY = (1LL << 32);

static const int dy4[] = {0, 0, 1, -1};
static const int dx4[] = {1, -1, 0, 0};
static const int dx8[] = {1, 1, 1, 0, 0, -1, -1, -1};
static const int dy8[] = {-1, 0, 1, -1, 1, -1, 0, 1};

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int K, S;
  cin >> K >> S;

  int cnt = 0;
  REP(X, K + 1) REP(Y, K + 1) REP(Z, K + 1) if (X + Y + Z == S) cnt++;

  cout << cnt << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;

#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

#define vint(v, n)                                                             \
  vector<int> v(n);                                                            \
  REP(i, n) cin >> v[i];
#define vlint(v, n)                                                            \
  vector<ll int> v(n);                                                         \
  REP(i, n) cin >> v[i];
#define vdouble(v, n)                                                          \
  vector<double> v(n);                                                         \
  REP(i, n) cin >> v[i];
#define vvdoube(v, n1, n2)                                                     \
  vector<vector<double>> v(n1, vector<double>(n2, 0));                         \
  REP(i, n1) REP(j, n1) cin >> v[i][j];
#define string(x)                                                              \
  string x;                                                                    \
  cin >> x;
#define vstring(v, n)                                                          \
  vector<string> v(n);                                                         \
  REP(i, n) {                                                                  \
    string a;                                                                  \
    std::cin >> a;                                                             \
    v.push_back(a);                                                            \
  }

#define all(v) (v).begin(), (v).end()
#define rall(v) (v).begin(), (v).end(), std::greater<int>()

static const string
    abet("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
static const long long int MOD = 1000000007;
static const double PI = 3.1415926535897932;
static const int INF = 0x3f3f3f3f;
static const int INFTY = (1 << 29);
static const long long LINFTY = (1LL << 32);

static const int dy4[] = {0, 0, 1, -1};
static const int dx4[] = {1, -1, 0, 0};
static const int dx8[] = {1, 1, 1, 0, 0, -1, -1, -1};
static const int dy8[] = {-1, 0, 1, -1, 1, -1, 0, 1};

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int K, S;
  cin >> K >> S;

  int cnt = 0;
  REP(X, K + 1) REP(Y, K + 1) if (S - X - Y >= 0 && S - X - Y <= K) cnt++;

  cout << cnt << endl;

  return 0;
}