Problem p03835 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define REP(i, x, n) for (int i = x; i < (int)n; i++)
#define rep(i, n) REP(i, 0, n)
#define sp(p) cout << setprecision(16) << fixed << p << endl;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define vout(v)                                                                \
  for (int i = 0; i < (int)v.size() - 1; i++) {                                \
    cout << v[i] << " ";                                                       \
  }                                                                            \
  cout << v[v.size() - 1] << "\n";
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL);
#define debg(a) cerr << #a << " " << a << endl;
#define show(a)                                                                \
  for (cont & y : a) {                                                         \
    for (cont & x : y) {                                                       \
      cout << x << " ";                                                        \
    }                                                                          \
    cout << endl;                                                              \
  }
template <class T> inline int out(const T &t) {
  print(t);
  putchar('\n');
  return 0;
}
template <class T> inline T gcd(T a, T b) {
  if (b == 0)
    return a;
  return (gcd(b, a % b));
}
template <class T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; }
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

void solve(long long K, long long S) {
  ll cnt = 0;
  for (ll i = 0; i <= K; i++) {
    for (ll j = 0; j <= K; j++) {
      for (ll k = 0; k <= K; k++) {
        i + j + k == S ? cnt++ : 0;
      }
    }
  }
  cout << cnt << "\n";
}

int main() {
  long long K;
  scanf("%lld", &K);
  long long S;
  scanf("%lld", &S);
  solve(K, S);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, x, n) for (int i = x; i < (int)n; i++)
#define rep(i, n) REP(i, 0, n)
#define sp(p) cout << setprecision(16) << fixed << p << endl;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define vout(v)                                                                \
  for (int i = 0; i < (int)v.size() - 1; i++) {                                \
    cout << v[i] << " ";                                                       \
  }                                                                            \
  cout << v[v.size() - 1] << "\n";
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL);
#define debg(a) cerr << #a << " " << a << endl;
#define show(a)                                                                \
  for (cont & y : a) {                                                         \
    for (cont & x : y) {                                                       \
      cout << x << " ";                                                        \
    }                                                                          \
    cout << endl;                                                              \
  }
template <class T> inline int out(const T &t) {
  print(t);
  putchar('\n');
  return 0;
}
template <class T> inline T gcd(T a, T b) {
  if (b == 0)
    return a;
  return (gcd(b, a % b));
}
template <class T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; }
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

void solve(long long K, long long S) {
  ll cnt = 0;
  for (ll i = 0; i <= K; i++) {
    for (ll j = 0; j <= K; j++) {
      ll tmp = S - (i + j);
      if (tmp <= K && tmp >= 0)
        cnt++;
      // for (ll k = 0; k <= K; k++) {
      //     i+j+k==S ? cnt++ : 0;
      // }
    }
  }
  cout << cnt << "\n";
}

int main() {
  long long K;
  scanf("%lld", &K);
  long long S;
  scanf("%lld", &S);
  solve(K, S);
  return 0;
}