Problem p03785 (C++)

Buggy submission (status: Runtime Error):
// 84104971101048411497 - Can you guess what does this mean?
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef complex<double> point;
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r)                                                       \
  fto(i, l, r) cout << a[i] << " ";                                            \
  cout << endl
#define fdto(i, r, l) for (int i = (r); i >= (l); --i)
#define fto(i, l, r) for (int i = (l); i <= (r); ++i)
#define forit(it, var)                                                         \
  for (__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define forrit(rit, var)                                                       \
  for (__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define X real()
#define Y imag()
#define maxN 55
#define maxC 2005
#define oo 1000000007
#define sz(a) (int)a.size()
#define EPS 1e-11

const double PI = acos(-1.0);

double fRand(double fMin, double fMax) {
  double f = (double)rand() / RAND_MAX;
  return fMin + f * (fMax - fMin);
}

template <class T> T min(T a, T b, T c) { return min(a, min(b, c)); }

template <class T> T max(T a, T b, T c) { return max(a, max(b, c)); }

int n, k, c, t[maxN];

int main() {
  scanf("%d%d%d", &n, &c, &k);
  fto(i, 1, n) scanf("%d", &t[i]);
  sort(t + 1, t + n + 1);

  int ans = 1, last = 1;
  fto(i, 2, n) {
    if (i == last + c || t[i] > t[last] + k) {
      ++ans;
      last = i;
    }
  }

  printf("%d", ans);

  return 0;
}


Fixed submission:
// 84104971101048411497 - Can you guess what does this mean?
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef complex<double> point;
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r)                                                       \
  fto(i, l, r) cout << a[i] << " ";                                            \
  cout << endl
#define fdto(i, r, l) for (int i = (r); i >= (l); --i)
#define fto(i, l, r) for (int i = (l); i <= (r); ++i)
#define forit(it, var)                                                         \
  for (__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define forrit(rit, var)                                                       \
  for (__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define X real()
#define Y imag()
#define maxN 100005
#define maxC 2005
#define oo 1000000007
#define sz(a) (int)a.size()
#define EPS 1e-11

const double PI = acos(-1.0);

double fRand(double fMin, double fMax) {
  double f = (double)rand() / RAND_MAX;
  return fMin + f * (fMax - fMin);
}

template <class T> T min(T a, T b, T c) { return min(a, min(b, c)); }

template <class T> T max(T a, T b, T c) { return max(a, max(b, c)); }

int n, k, c, t[maxN];

int main() {
  scanf("%d%d%d", &n, &c, &k);
  fto(i, 1, n) scanf("%d", &t[i]);
  sort(t + 1, t + n + 1);

  int ans = 1, last = 1;
  fto(i, 2, n) {
    if (i == last + c || t[i] > t[last] + k) {
      ++ans;
      last = i;
    }
  }

  printf("%d", ans);

  return 0;
}