おじさんの競プロ記録

自分の力で解答できた問題を振り返り、理解を深めたいです。

AtCoder Grand Contest 011 A - Airport Bus

問題について考えたこと

問題文へ

N人を、定員Cのバスに乗せます。Tiに到着し、K以内に乗せないといけません。

到着時間Tiはサンプルから、昇順に与えられないことがわかるのでソートしました。

最初に到着した人を乗せ、K以内に到着した人を定員Cまで乗せます。これを繰り返しました。

#define _GIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;


int main(void) {
  int N, C, K;
  cin >> N >> C >> K;
  vector<int> T(N);
  rep(i, N) cin >> T[i];

  sort(T.begin(), T.end());

  int i = 0;
  int ans = 0;
  while (i < N) {
    ++ans;
    int j = i + 1;
    while (j < N && j - i < C && T[i] + K >= T[j]) {
      ++j;
    }
    i = j;
  }

  cout << ans << endl;
  
  return 0;
}