Problem p03920 (C++)

Buggy submission (status: Time Limit Exceeded):
// ------------------------------------
// Date:2018/ 3/20
// Problem:Exactly N points b.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i, a) for (auto &i : a)
#define FOR(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RFOR(i, a, b) for (int i = (int)b - 1; i >= (int)a; --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") <<　endl;
typedef long long ll;

void CINT() {}
template <class Head, class... Tail> void CINT(Head &&head, Tail &&...tail) {
  cin >> head;
  CINT(move(tail)...);
}
#define CIN(...)                                                               \
  int __VA_ARGS__;                                                             \
  CINT(__VA_ARGS__)
#define LCIN(...)                                                              \
  ll __VA_ARGS__;                                                              \
  CINT(__VA_ARGS__)
#define SCIN(...)                                                              \
  string __VA_ARGS__;                                                          \
  CINT(__VA_ARGS__)

static const int MOD = 1e9 + 7;
static const int MAX_N = 1e7 + 1;

int main() {
  int N;
  scanf("%d", &N);
  int t;
  FOR(i, 1, MAX_N) {
    ll tmp = (1 + i) * i / 2;
    if (tmp >= N)
      break;
    t = i + 1;
  }
  for (int i = t; i > 0; --i) {
    if (N >= i) {
      printf("%d\n", i);
      N -= i;
    }
  }

  return 0;
}


Fixed submission:
// ------------------------------------
// Date:2018/ 3/20
// Problem:Exactly N points b.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i, a) for (auto &i : a)
#define FOR(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RFOR(i, a, b) for (int i = (int)b - 1; i >= (int)a; --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") <<　endl;
typedef long long ll;

void CINT() {}
template <class Head, class... Tail> void CINT(Head &&head, Tail &&...tail) {
  cin >> head;
  CINT(move(tail)...);
}
#define CIN(...)                                                               \
  int __VA_ARGS__;                                                             \
  CINT(__VA_ARGS__)
#define LCIN(...)                                                              \
  ll __VA_ARGS__;                                                              \
  CINT(__VA_ARGS__)
#define SCIN(...)                                                              \
  string __VA_ARGS__;                                                          \
  CINT(__VA_ARGS__)

static const int MOD = 1e9 + 7;
static const int MAX_N = 1e7 + 1;

int main() {
  int N;
  scanf("%d", &N);
  int t = 1;
  REP(i, MAX_N) {
    ll tmp = (1 + i) * i / 2;
    if (tmp >= N)
      break;
    t = i + 1;
  }
  for (int i = t; i > 0; --i) {
    if (N >= i) {
      printf("%d\n", i);
      N -= i;
    }
  }

  return 0;
}