Problem:


Score : 300 points

Problem Statement

Every day, N passengers arrive at Takahashi Airport.
The i-th passenger arrives at time T_i.

Every passenger arrived at Takahashi airport travels to the city by bus. Each bus can accommodate up to C passengers.
Naturally, a passenger cannot take a bus that departs earlier than the airplane arrives at the airport.
Also, a passenger will get angry if he/she is still unable to take a bus K units of time after the arrival of the airplane.
For that reason, it is necessary to arrange buses so that the i-th passenger can take a bus departing at time between T_i and T_i + K (inclusive).

When setting the departure times for buses under this condition, find the minimum required number of buses.
Here, the departure time for each bus does not need to be an integer, and there may be multiple buses that depart at the same time.

Constraints

2 \leq N \leq 100000

1 \leq C \leq 10^9

1 \leq K \leq 10^9

1 \leq T_i \leq 10^9

C, K and T_i are integers.

Input

The input is given from Standard Input in the following format:

N C K
T_1
T_2
:
T_N

Output

Print the minimum required number of buses.

Sample Input 1

5 3 5
1
2
3
6
12

Sample Output 1

3

For example, the following three buses are enough:

A bus departing at time 4.5, that carries the passengers arriving at time 2 and 3.

A bus departing at time 6, that carries the passengers arriving at time 1 and 6.

A bus departing at time 12, that carries the passenger arriving at time 12.

Sample Input 2

6 3 3
7
6
2
8
10
6

Sample Output 2

3



Sample input:
5 3 5
1
2
3
6
12


Sample output:
3

Submission status: Accepted

Solution code:
N,C,K=map(int,input().split())
T=[int(input())for i in range(N)]
T.sort()
ans=0
bus_seat=0
tmp_time=0
for i in range(len(T)):
    if T[i]>tmp_time+K:
        bus_seat=0
    if bus_seat==0:
        ans+=1
        tmp_time=T[i]
    
    bus_seat+=1
    if bus_seat==C:
        bus_seat=0
print(ans)

Submission status: Accepted

Solution code:
N,C,K=map(int,input().split())
import heapq
T=[]
heapq.heapify(T)
for i in range(N):
    heapq.heappush(T,int(input()))

ans=1
p=1
start=heapq.heappop(T)

for i in range(N-1):
    t=heapq.heappop(T)
    p+=1
    if p<=C and t<=start+K:
        continue
    else:
        start=t
        ans+=1
        p=1

print(ans)

Submission status: Accepted

Solution code:
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal

sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===
def main():
    n, c, k = ns()
    t = [ni() for _ in range(n)]
    t.sort()

    ans = 0
    idx = 0
    while idx < n:
        ans += 1

        k_idx = bisect.bisect_right(t, t[idx] + k)
        c_idx = idx + c

        idx = min(k_idx, c_idx)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy

# import heapq
# from collections import deque
# import decimal

sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===
def main():
    n, c, k = ns()
    t = [ni() for _ in range(n)]
    t.sort()

    ans = 0
    idx = 0
    while True:
        ans += 1

        k_idx = bisect.bisect_right(t, t[idx] + k)
        c_idx = idx + c

        idx = min(k_idx, c_idx)
        if idx > n-1:
            break

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, c, k = map(int, input().split())
t = [int(input()) for i in range(n)]
t.sort()
cnt = 1
buss = 0
fir = t[0]
for i in range(1, n):
    if fir <= t[i] and t[i] <= fir + k and cnt < c:
        cnt += 1
    else:
        buss += 1
        cnt = 1
        fir = t[i]
if cnt >= 1:
    buss += 1
print(buss)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N, C, K = map(int, input().split())
    T = [int(input()) for _ in range(N)]
    T.sort()

    first = T[0]
    cnt = 1
    ans = 0
    for i in range(1, N):
        if cnt == C:
            ans += 1
            first = T[i]
            cnt = 1
        elif first + K < T[i]:
            ans += 1
            first = T[i]
            cnt = 1
        else:
            cnt += 1
    ans += 1

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n,c,k=map(int,input().split())
t=[]
for _ in range(n):
    t.append(int(input()))
t.sort()

def bus(M):
    j=1
    count=0
    I=t[0]
    for i in range(n):
        if I+k>=t[i] and count<c: 
            count+=1
        else:
            I=t[i]
            count=1
            j+=1
    if j<=M:
        return True
    else:
        return False

start=0
end=n
while end-start>1:
    ty=(start+end)//2
    if bus(ty):
        end=ty
    else:
        start=ty
print(end)

Submission status: Accepted

Solution code:
n,c,k = map(int,input().split())
l = sorted(list(int(input()) for _ in range(n)))
bus = 1
now = 1
time = l[0]+k
for i in range(1,n):
  b = l[i]
  if b<=time and time<=b+k and now<c:
    now += 1
  else:
    bus += 1
    now = 1
    time = l[i]+k
print(bus)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,c,k=mp()
t=sorted([int(input()) for i in range(n)])
count=1
f=t[0]
ans=1
for i in range(1,n):
    count+=1
    d=t[i]-f
    if d>k or count>c:
        ans+=1
        count=1
        f=t[i]

print(ans)

Submission status: Accepted

Solution code:
n, c, k = map(int, input().split())
t = [int(input()) for _ in range(n)]
t.sort()

t_crr = t[0]
cnt = 0
ans = 1

for i in t:
    # print(cnt, ans, t_crr, i)
    if i - t_crr <= k and cnt < c:
        cnt += 1
        continue
    else:
        t_crr = i
        ans += 1
        cnt = 1

print(ans)

Submission status: Accepted

Solution code:


n, c, k = map(int, input().split())
t = [int(input()) for _ in range(n)]
t.sort(reverse=True)

t_b = t[0]
cnt = 0
ans = 0

for i in t:
    # print(i, t_b, cnt, ans)
    if t_b - i <= k and cnt + 1 <= c: # 差がk以下で人数に余裕がある
        cnt += 1
        continue
    else:
        t_b = i
        cnt = 1
        ans += 1

print(ans + 1)

Submission status: Accepted

Solution code:
N,C,K = map(int,input().split())
T = [int(input()) for _ in range(N)]
T.sort()
bus = 0
count = 0
j = 0
for i in range(N-1):
  count += 1
  if count >= C or T[i+1] > T[j]+K:
    bus += 1
    j += count
    count = 0
  if i == N-2:
    count += 1
    if count%C == 0:
      bus += count//C
    else:
      bus += count//C+1
print(bus)

Submission status: Accepted

Solution code:
N, C, K = map(int,input().split())
T = [int(input()) for i in range(N)]
T.sort(reverse = True)
counter = 1
i = 0           #### whileの中のカウント（バス乗車数）
A = T.pop()     #####先頭
while T:
  a = T.pop()
  i+=1
  if i>=C or a>A+K:
    i=0
    A=a
    counter += 1
  
print(counter)

Submission status: Accepted

Solution code:
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N,C,K = list(map(int,_in[0].split(' ')))  # type:list(int)
    T_arr = []
    for i in range(N):
        _ = int(_in[i+1])  # type:int
        T_arr.append(_)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    T_arr.sort()
    cnt = 0
    i = 0
    while True:
        c = 1
        tlim = T_arr[i]+K
        i += 1
        while i<N and T_arr[i]<=tlim and c+1<=C:
            i += 1
            c += 1
        cnt += 1
        if i>=N:
            break
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def main():
    N, C, K = map( int, input().split())
    T = [ int( input()) for _ in range(N)]
    T.sort()
    deadline = -1
    ans = 0
    count = 0
    for t in T:
        if deadline < t or count >= C:
            ans += 1
            deadline = t+K
            count = 1
            continue
        count += 1

    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7



def main():
    n, c, k = map(int, input().split())
    t = [int(input()) for _ in range(n)]

    t.sort()

    waitP = 1
    l = t[0]
    ans = 0

    for i in range(1, n):
        if waitP == c:
            ans += 1
            l = t[i]
            waitP = 1
            if i == n - 1:
                ans += 1
        elif waitP != c:
            if t[i] - l <= k:
                waitP += 1
                if i == n - 1:
                    ans += 1
            elif t[i] - l > k:
                ans += 1
                l = t[i]
                waitP = 1
                if i == n - 1:
                    ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import deque
n,c,k = map(int,input().split())
t = []
for _ in range(n):
    tt = int(input())
    t.append(tt)
t.sort()
ans = deque([])
cnt = 0
for i, tt in enumerate(t):
    if i == 0:
        ans.append([tt+k,1])
        cnt += 1
    else:
        flg = False
        for i in range(len(ans)):
            tmp = ans.popleft()
            if tmp[0] < tt or tmp[1] == c:

                continue
            else:
                flg = True
                break
        if flg :
            tmp[1] += 1
            if tmp[1] != c:
                ans.appendleft(tmp)
        else:
            tmp = [tt+k,1]
            ans.append(tmp)
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import numpy as np
n,c,k=map(int,input().split())
t=list(int(input()) for _ in range(n))
t.sort()
t=np.array(t)
s=0
num=0
while True:
    e=np.searchsorted(t,t[s]+k,side="right")
    if e-s>c:
        s=s+c
    else:
        s=e
    num+=1
    if s>n-1:
        break
print(num)

Submission status: Accepted

Solution code:
n, c, k = map(int, input().split())
t = [int(input()) for _ in range(n)]

t.sort()

waitP = 1
l = t[0]
ans = 0

for i in range(1, n):
    if waitP == c:
        ans += 1
        l = t[i]
        waitP = 1
        if i == n - 1:
            ans += 1
    elif waitP != c:
        if t[i] - l <= k:
            waitP += 1
            if i == n - 1:
                ans += 1
        elif t[i] - l > k:
            ans += 1
            l = t[i]
            waitP = 1
            if i == n - 1:
                ans += 1

print(ans)

Submission status: Accepted

Solution code:
N,C,K = map(int,input().split())
lisT = [int(input()) for _ in range(N)]

lisT.sort()
teiin = C
limit = K
timeup = 0
passengers = C
buscnt = 0
for i in range(N):
    if lisT[i] > timeup or passengers==0:
        timeup = lisT[i] + K
        passengers = C
        buscnt += 1
        passengers -= 1
    else:
        passengers -= 1

print(buscnt)

Submission status: Accepted

Solution code:
n, c, k = map(int, input().split())
t = []
for _ in range(n):
    t.append(int(input()))
t.sort()
ans = 1
bus = 0
d_time = t[0]+k
for i in t:
    if i>d_time or bus==c:
        ans += 1
        bus = 1
        d_time = i+k
    else:
        bus += 1
print(ans)

Submission status: Accepted

Solution code:
def myAnswer(N:int,C:int,K:int,T:list)->int:
   T.sort()
   ans = 0
   counter = 1
   hantei = T.pop(0)
   for t in T:
      if(counter == C or (t - hantei) > K):
         ans += 1
         hantei = t
         counter = 1
      else:
         counter += 1
   ans += 1
   return ans

def modelAnswer():
   return
def main():
   N,C,K = map(int,input().split())
   T = [int(input()) for _ in range(N)]
   print(myAnswer(N,C,K,T))

if __name__ == '__main__':
   main()

Submission status: Accepted

Solution code:
n,c,k=map(int,input().split())

cnt=0


time=[]
for _ in range(n):
    time.append(int(input()))


time.sort()

count_up=0
member=0
cnt=0

temp=[]

for t in time:
    if count_up==0:
        count_up=t

    if t>count_up+k:
        #print(temp)
        cnt+=1
        count_up=t
        member=1
        temp=[t]
    else:
        member+=1
        temp.append(t)
        if member>=c:
            #print(temp)
            member=0
            cnt+=1
            count_up=0
            temp=[]

if member>0:
    cnt+=1
    #print(temp)

print(cnt)

Submission status: Accepted

Solution code:
N, C, K, *T = map(int, open(0).read().split())
T.sort()

ans = 1
curm = T[0]
curc = 0
for t in T:
    curc += 1
    if t > curm+K or curc > C:
        ans += 1
        curm = t
        curc = 1
print(ans)

Submission status: Accepted

Solution code:
N, C, K = map(int, input().split())
bus_count = 0
waiting_count = 0
time_limit = 0
D = [int(input()) for _ in range(N)]
D.sort()
# C == 1の場合にあロジックが崩壊してしまうわ
for i in range(N):
    T = D[i]
    waiting_count += 1
    if T > time_limit and not time_limit == 0:
        time_limit = T + K
        bus_count += 1
        waiting_count = 1
    if waiting_count == C:
        bus_count += 1
        waiting_count = 0
        time_limit = 0
    else:
        if waiting_count == 1:
            time_limit = T + K

if not waiting_count == 0:
    print(bus_count+1)
else:
    print(bus_count)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n,c,k = map(int, input().split())
t = list(int(input()) for i in range(n))
t.sort()
ans =0

from collections import deque
queue = deque()

INF = float('inf')
t.append(INF)

for i in range(n):

    queue.append(t[i])
    limit = queue[0]+k

    if limit < t[i+1] or len(queue)>=c:
        for i in range(min(len(queue), c)):
            queue.popleft()
        ans += 1

while queue:
    for i in range(min(len(queue), c)):
        queue.popleft()
    ans += 1

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
n, c, k = [int(a) for a in input().split()]
t = []
for _ in range(n):
    t.append(int(input()))
t = np.asarray(t)
t = np.sort(t)

ans = 0
count = 0
lim = 0

for i in range(t.shape[0]):
    if count == 0:
        lim = t[i] + k
        count += 1
    elif t[i] <= lim and count < c:
        count += 1
    else:
        lim = t[i] + k
        ans += 1
        count = 1

print(ans+1)

Submission status: Accepted

Solution code:
n , c , k = map(int,input().split())
t = [int(input()) for i in range(n)]
t.sort()

ans = 0
cou = 0
lim = 0

for i in range(n):
    if lim == 0:
        lim = t[i] + k
        cou = 1
        if c == 1:
            lim = 0
            cou = 0
            ans += 1
    elif lim > t[i]:
        if cou == c - 1:
            ans += 1
            cou = 0
            lim = 0
        elif cou < c - 1:
            cou += 1
    elif lim == t[i]:
        ans += 1
        cou = 0
        lim = 0
    elif lim < t[i]:
        ans += 1
        cou = 1
        lim = t[i] + k

if cou > 0:
    ans += 1

print(ans)

Submission status: Accepted

Solution code:
n, c, k = map(int, input().split())

begin = 0

t = 0
cap = 0

L = []
for i in range(n):
    L.append(int(input()))
L = sorted(L)
for i in range(n):
    a = L[i]
    if begin == 0:
        begin = a
    if a <= begin + k and cap < c:
        cap += 1
    else:
        t += 1
        begin = a
        cap = 1
print(t +1)

Submission status: Accepted

Solution code:
n,c,k = map(int,input().split())
t = []
for i in range(n):
  t.append(int(input()))

ans = 0
t.sort()
x = 0
p = 0
for ti in t:
  if x < ti:
    ans += 1
    p = 1
    x = ti+k
  else:
    if p < c:
      p += 1
    else:
      ans += 1
      p = 1
      x = ti+k
print(ans)

Submission status: Accepted

Solution code:
N, C, K = map(int, input().split())

T = [int(input()) for _ in range(N)]

T.sort()

res = 0
i = 0
while i < N:
	res += 1
	Left = i
	while (i < N and T[i] - T[Left] <= K and i - Left + 1 <= C):
		i += 1

print(res)

Submission status: Accepted

Solution code:
n,c,k=map(int,input().split())
customer=[int(input()) for i in range(n)]
customer=sorted(customer)
limit=-1
cnt=0
ans=0
for i in range(n):
    if cnt==0:
        limit=customer[i]+k
        cnt+=1
    else:
        if customer[i]>limit:
            ans+=1
            cnt=1
            limit=customer[i]+k
        else:
            if cnt<c:
                cnt+=1
            else:
                ans+=1
                cnt=1
                limit=customer[i]+k
if cnt>0:
    ans+=1
print(ans)

Submission status: Accepted

Solution code:
n, c, k = map(int, input().split())
times = []
for i in range(n):
    times.append(int(input()))
    
times.sort()

passenger = 0
number_of_unit = 1
waiting_time = times[0] + k
for t in times:
    if c == passenger:
        #print('c < passenger', t)
        passenger = 0
    elif waiting_time < t:
        #print('waiting_time < t', t)
        passenger = 0
    else:
        #print('else',t)
        passenger += 1
        
    if passenger == 0:
        waiting_time = t + k
        passenger += 1
        number_of_unit += 1
        #print('-------','new_bus',waiting_time,'-------')

print(number_of_unit)

Submission status: Accepted

Solution code:
N, C, K = map(int,input().split())
T = [int(input()) for i in range(N)]

T.sort(reverse=True)

#print(T)
t_before = T[0]
cnt = 0
ans = 0
for t in T:
    #print(t, t_before, cnt, ans)
    if t_before - t <= K and cnt + 1 <= C:
        cnt += 1
        continue
    else:
        t_before = t
        cnt = 1
        ans += 1

print(ans+1)

Submission status: Accepted

Solution code:
N, C, K = map(int, input().split())
T = []
for _ in range(N):
    x = int(input())
    T.append(x)
T.sort()
lim = 0
tim = 0
ans = 0
for i in range(N):
    if lim == 0:
        lim += 1
        tim = T[i]
    else:
        if tim + K >= T[i] and lim < C:
            lim += 1
        else:
            lim = 1
            tim = T[i]
            ans += 1

print(ans+1)

Submission status: Accepted

Solution code:
n, c, k = map(int, input().split())
t = [0] * n
for i in range(n):
    t[i] = int(input())

t.sort()
ans = 0
now_person = 0
first_lim = 0
for i in range(n):
    if now_person == 0:
        first_lim = t[i]
        now_person = 1
        ans += 1
    else:
        if t[i] - first_lim  <= k:
            now_person += 1
        else:
            first_lim = t[i]
            now_person = 1
            ans += 1

    #print(i, t[i], now_person, first_lim, ans)

    if now_person == c:
        now_person = 0

print(ans)

Submission status: Accepted

Solution code:
#バスの定員C人　Ti <= Ti + kのバスに乗りたい
n,c,k = map(int, input().split())
t = list(int(input()) for _ in range(n))
t.sort()

T = 0
x = 0
ans = 0
for i in range(n):
    if x == 0: #誰も待ってない状態
        T = t[i] + k
        x += 1
    elif t[i] <= T: #バス待ってる人
        x += 1
    elif t[i] > T: #time over
        ans += 1
        x = 1
        T = t[i] + k
    if x == c: #定員に達していたらバス出発
        ans += 1
        T = 0
        x = 0
if x != 0: ans += 1
print(ans)

Submission status: Accepted

Solution code:
N,C,K = map(int,input().split())
T = [int(input()) for _ in range(N)]
T.sort()

i = 0
ans = 0
while i < N:
  tmp = i+1
  while tmp < N:
    if tmp < i+C and T[tmp] <= T[i]+K:
      tmp += 1
    else:
      break
  ans += 1
  i = tmp
print(ans)

Submission status: Accepted

Solution code:
n,c,k = map(int,input().split()) #ｎが合計人数、ｃが定員、ｋが時間
t = [int(input()) for _ in range(n)]
t = sorted(t)
count = 0
bus = []
for i in range(0,n):
    if len(bus)>0: #バスに人が１人以上いるとき
        if  c <= len(bus): #バスに人がｃ人以上いるとき⇒出発する
            count += 1
            bus = []
            
        if len(bus)>0 and k < t[i]-bus[0]: #人が１人以上いて時間が過ぎてしまうとき
            count += 1
            bus = [t[i]]
        else:
            bus.append(t[i])
    else:
        bus.append(t[i])
        
    if i==n-1:
        if len(bus)>0:
            count += 1
            bus = []
print(count)

Submission status: Accepted

Solution code:
n,c,k=map(int,input().split())
t=[0 for i in range(n)]
for i in range(n):
    t[i]=int(input())
t.sort()
ans=0
cnt=1
bef=t[0]
for i in range(1,n):
    if cnt==c:
        ans+=1
        cnt=1
        bef=t[i]
    elif bef+k>=t[i] and cnt<c:
        cnt+=1
    else:
        ans+=1
        cnt=1
        bef=t[i]
    if i==n-1:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
N, C, K = map(int, input().split())
arr = sorted([int(input()) for _ in range(N)])
start_t = arr[0]
bus_n = 0
ans = 1
for i in range(N):
    if arr[i] <= start_t + K and bus_n < C:
        bus_n += 1
    else:
        bus_n = 1
        start_t = arr[i]
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.buffer.readline

N, C, K = map(int, input().split())
T = [int(input()) for _ in range(N)]
T.sort()

lim = 0
ans = 0
wait = 0
for t in T:
    if t > lim:
        if wait:
            ans += 1
        if C == 1:
            ans += 1
            wait = 0
            lim = 0
        else:
            lim = t + K
            wait = 1
    else:
        wait += 1
        if wait == C:
            ans += 1
            wait = 0
            lim = 0
if wait:
    ans += 1

print(ans)

Submission status: Accepted

Solution code:
n, c, k = map(int, input().split())
t_list = []
for i in range(n):
    t_list.append(int(input()))
t_list.sort()
count = 1
current_c = []
start_t = None


for t in t_list:
    if not start_t:
        start_t = t
        current_c.append(t)
    elif len(current_c) < c:
        if start_t + k < t:
            count += 1
            current_c = [t]
            start_t = t
        else:
            current_c.append(t)
    elif len(current_c) >= c:
        count += 1
        current_c = [t]
        start_t = t
    else:
        print("error")
print(count)

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, C, K = MAP()
A = [INT() for i in range(N)]
num = 0
A.sort()
B = []
ans = 0
mi = 0
# print(A)
for i in range(N):
    if len(B) == C:
        # 超えていたら
        B = [A[i]]
        ans += 1
        mi = A[i]
    elif len(B) == 0:
        B = [A[i]]
        mi = A[i]
    else:
        gap = A[i] - mi
        if gap <= K:
            B.append(A[i])
        else:
            B = [A[i]]
            ans += 1
            mi = A[i]
    # print(B)
if len(B) != 0:
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n,c,k=map(int,input().split())
    ans=0
    person=0
    wait=-10**9
    T=[int(input())for _ in range(n)]
    T.sort()
    for i in range(n):
        if T[i]-wait<=k and person+1<=c:
            person+=1
        else:
            ans+=1
            person=1
            wait=T[i]
    print(ans)

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
n,c,k=map(int,input().split())
a=[int(input()) for _ in range(n)]

a.sort()
count=0
c_count=1
box=a[0]
for i in range(1,n):
    if c_count<c:
        if a[i]-box<=k:
            count+=1
            c_count+=1
        else:
            box=a[i]
            c_count=1
    else:
        box=a[i]
        c_count=1
    #print(count)
print(n-count)

Submission status: Accepted

Solution code:
n,c,k = map(int,input().split())
t = sorted([int(input()) for i in range(n)])
ans = 0
j = 1
rimit = 0
for i in t:
    if j<c and rimit>=i:
        j+=1
    else:
        ans+=1
        rimit=i+k
        j=1
print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, c, k = map(int, input().split())
    T = sorted(list(int(input()) for _ in range(n)))
    res = 0
    cnt = 0
    dep = T[0] + k
    for i in range(n):
        if cnt == c or T[i] > dep:
            res += 1
            cnt = 1
            dep = T[i] + k
        else:
            cnt += 1

    print(res + 1)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
from sys import stdin
import sys
import math

[N, C, K] = list(map(int, stdin.readline().rstrip().split()))
T = sorted([int(input()) for i in range(N)])

bus = 1
passenger = 0
first_passengers_time = -1
for i in T:
    if passenger == C or (passenger > 0 and first_passengers_time + K < i):
        bus += 1
        passenger = 0
        first_passengers_time = 0

    if passenger == 0:
        passenger += 1
        first_passengers_time = i
    elif passenger < C and first_passengers_time + K >= i:
        passenger += 1

print(bus)

Submission status: Accepted

Solution code:
N, C, K = map(int, input().split(' '))
T = [int(input()) for _ in range(N)]
T.sort()
ans = 1
bus_cap = 1
last_time = T[0]
for t in T[1:]:
    if bus_cap + 1 > C or t - last_time > K:
        ans += 1
        bus_cap = 1
        last_time = t
    else:
        bus_cap += 1
print(ans)

Submission status: Accepted

Solution code:
n,c,k = map(int,input().split())
li = []
for _ in range(n):
    li.append(int(input()))
li.sort()

all_count = 0
kazu = 0
start = 0
if c == 1:
    print(n)
    exit()
for l in li:
    if kazu == 0 and start == 0:
        all_count += 1
        kazu += 1
        start = l
        continue
    if kazu < c and l - start <= k:
        kazu += 1
    if kazu == c:
        kazu = 0
        start = 0
        continue
    if l - start > k:
        all_count += 1
        kazu = 1
        start = l
print(all_count)

Submission status: Accepted

Solution code:
n,c,k = map(int,input().split())
ab = []
for _ in range(n):
    t=int(input())
    ab.append(t)
ab.sort()

bus = 1
bustime = ab[0] + k
customer = 1

for i in range(1,n):
    if customer < c and ab[i] <= bustime:
        customer += 1
    else:
        bustime = ab[i]+k
        customer = 1
        bus += 1
print(bus)

Submission status: Accepted

Solution code:
n,c,k = map(int,input().split())
t = [int(input()) for i in range(n)]

t.sort()

bus = 0
dis = t[0] + k
temp = 0 

for i in range(n):
    if (t[i] > dis) or (temp+1 > c):
        bus += 1
        dis = t[i]+k
        temp = 1
        
        
    else:
        temp += 1
            
    

print(bus+1)

Submission status: Accepted

Solution code:
import collections

n, c, k = map(int, input().split())
t = [int(input()) for i in range(n)]

t.sort()

passenger = 0
departure_limit = t[0] + k
bus_cnt = 0

for T in t:
    if passenger+1 > c or T > departure_limit:
        departure_limit = T+k
        passenger = 1
        bus_cnt += 1
    else:
        passenger+=1

print(bus_cnt+1)

Submission status: Accepted

Solution code:
N, C, K = map(int, input().split())
T = [int(input()) for i in range(N)]
sorted_T = sorted(T)

first = sorted_T[0]
cap = C-1
limit = first + K
ans = 1

for i in range(1, N):
    if (cap > 0) and (sorted_T[i] < limit):
        cap -= 1
    elif (cap == 0) or ((cap > 0) and (sorted_T[i] > limit)):
        cap = C-1
        first = sorted_T[i]
        limit = first + K
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
import bisect
import sys
def input(): return sys.stdin.readline().strip()


N, C, K = map(int, input().split())
T = sorted([int(input()) for i in range(N)])

TT = [i + K for i in T]

cnt = 0
i = 0
temp = -1  # temp番まで運び終わった
while True:
    i = bisect.bisect_right(T, TT[i])
    if i - temp > C:
        i = temp + C + 1
        temp += C
    cnt += 1
    temp = i - 1
    if i >= N:
        break
print(cnt)

Submission status: Accepted

Solution code:
import bisect
# from collections import Counter, deque # https://note.nkmk.me/python-scipy-connected-components/
# from copy import copy, deepcopy
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    N, C, K = map(int, input().split())
    T = sorted([int(input()) for i in range(N)])

    TT = [i + K for i in T]

    cnt = 0
    i = 0
    temp = -1
    while True:
        i = bisect.bisect_right(T, TT[i])
        if i - temp > C:
            i = temp + C + 1
            temp += C
        cnt += 1
        temp=i-1
        if i >= N:
            break
    print(cnt)


resolve()

Submission status: Accepted

Solution code:
# python3.4.2用
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def lprint(l): print(*l, sep='\n')

# Nが乗客の人数
# Cがバスの定員
# Kが飛行機が到着から起こりだす時間
# Tが到着時刻
# T <= X <= T+Kとする必要あり
N,C,K = imn()
T = sorted([iin() for _ in range(N)])

departure_time = -1
passenger_cnt = 0
ans = 0
if C == 1:
    print(N)
    exit()
    
for i in range(N):
    if departure_time == -1: 
        departure_time = T[i] + K
        passenger_cnt += 1
        ans += 1
    else:
        if departure_time >= T[i]:
            passenger_cnt += 1 
            if passenger_cnt == C:
                departure_time = -1
                passenger_cnt = 0
        else:
            departure_time = T[i]+K
            passenger_cnt = 1
            ans += 1 
print(ans)