Problem p03835 (C++)

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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define ALLTRUE(xs) all_of(ALL(xs), [](bool x) { return x; })
#define AND(x, y, z)                                                           \
  set_intersection((x).begin(), (x).end(), (y).begin(), (y).end(),             \
                   inserter((z), (z).end()))
#define ANYTRUE(xs) any_of(ALL(xs), [](bool x) { return x; })
#define CONCAT(x, y) (x).insert((x).end(), (y).begin(), (y).end())
#define DUMP(xs)                                                               \
  for (auto x : xs)                                                            \
    cout << x << ' ';                                                          \
  cout << endl
#define DUMPP(xs)                                                              \
  for (auto x : xs)                                                            \
    cout << '(' << x.first << ',' << x.second << ')';                          \
  cout << endl
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define OR(x, y, z)                                                            \
  set_union((x).begin(), (x).end(), (y).begin(), (y).end(),                    \
            inserter((z), (z).end()))
#define OUT(x) cout << x << endl
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef pair<ll, ll> P;

struct edge {
  int to, cost;
};

int main() {
  int K, S;
  cin >> K >> S;

  set<vector<int>> ts;
  REP(x, K + 1) REP(y, K + 1) {
    int z = S - x - y;
    if (z < 0 || z > K)
      continue;
    vector<int> t{x, y, z};
    sort(ALL(t));
    ts.insert(t);
  }

  int ans = 0;
  for (auto t : ts) {
    if (t[0] == t[1] && t[1] == t[2])
      ans++;
    else if (t[0] == t[1] || t[1] == t[2])
      ans += 3;
    else
      ans += 6;
  }
  OUT(ans);

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define ALLTRUE(xs) all_of(ALL(xs), [](bool x) { return x; })
#define AND(x, y, z)                                                           \
  set_intersection((x).begin(), (x).end(), (y).begin(), (y).end(),             \
                   inserter((z), (z).end()))
#define ANYTRUE(xs) any_of(ALL(xs), [](bool x) { return x; })
#define CONCAT(x, y) (x).insert((x).end(), (y).begin(), (y).end())
#define DUMP(xs)                                                               \
  for (auto x : xs)                                                            \
    cout << x << ' ';                                                          \
  cout << endl
#define DUMPP(xs)                                                              \
  for (auto x : xs)                                                            \
    cout << '(' << x.first << ',' << x.second << ')';                          \
  cout << endl
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define OR(x, y, z)                                                            \
  set_union((x).begin(), (x).end(), (y).begin(), (y).end(),                    \
            inserter((z), (z).end()))
#define OUT(x) cout << x << endl
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef pair<ll, ll> P;

struct edge {
  int to, cost;
};

int main() {
  int K, S;
  cin >> K >> S;

  set<vector<int>> ts;
  REP(x, K + 1) FOR(y, x, K + 1) {
    int z = S - x - y;
    if (z < 0 || z > K)
      continue;
    vector<int> t{x, y, z};
    sort(ALL(t));
    ts.insert(t);
  }

  int ans = 0;
  for (auto t : ts) {
    if (t[0] == t[1] && t[1] == t[2])
      ans++;
    else if (t[0] == t[1] || t[1] == t[2])
      ans += 3;
    else
      ans += 6;
  }
  OUT(ans);

  return 0;
}