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 = list(map(int, input().split()))

T = []
for i in range(N):
	T.append(int(input()))

T = sorted(T)

TT = []

for i in range(N - 1):
	TT.append(T[i + 1] - T[i])

ans = 1
c = 1
t = 0

for i in range(N - 1):
	t += TT[i]
	c += 1
	if t > K:
		ans += 1
		t = 0
		c = 1

	if c > C:
		ans += 1
		t = 0
		c = 1

print(ans)

Submission status: Accepted

Solution code:
from operator import itemgetter
from math import ceil
N, C, K = map(int, input().split())
T = []
for i in range(N):
  T.append(int(input()))
  
T.sort()
i=0
ans=0
while i < N:
  buscnt = 0
  tlimit = T[i] + K
  while i < N and T[i] <= tlimit and buscnt < C:
    buscnt += 1
    i += 1
  if i==N:
    break
  
  #print(i,T[i],tlimit)
  ans += 1

if buscnt > 0:
  ans += 1

print(ans)

Submission status: Accepted

Solution code:
n,c,k=map(int,input().split())
t=[int(input()) for i in range(n)]
t.sort()
a=t[0];b=1;d=0
for j in range(n):
  d+=1
  if t[j]>a+k or d>c:
     a=t[j]
     b+=1
     d=1
print(b)

Submission status: Accepted

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

res = 0
count_teiin = 0
prev_bus = -1
for i in t:
    # 前のバスが行ってしまったら、i分に出発するバスを手配
    if prev_bus == -1 or prev_bus+k < i:
        res += 1
        prev_bus = i
        count_teiin = 1
    else:
        count_teiin += 1
    # 定員になったら出発
    if count_teiin == c:
        prev_bus = -1
print(res)

Submission status: Accepted

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

Ts.sort()

num = 1
limT = Ts[0] + K
ans = 0
for T in Ts[1:]:
    if limT < T or num == C:
        # バス出発
        num = 1
        limT = T + K
        ans += 1
    else:
        num += 1

print(ans)

Submission status: Accepted

Solution code:
n, c, k=map(int, raw_input().split())
t=[input() for i in range(n)]
t.sort()
result=0
cap=0
time=-1
for cur in t:
	if cap==0 or time+k<cur:
		result+=1
		cap=c
		time=cur
	cap-=1
print result

Submission status: Accepted

Solution code:
n, c, k = map(int, input().split())
t = sorted([int(input()) for _ in range(n)])
bus = []
count = 0
p = t.pop(0)
bus.append(p)
while t != []:
    p = t.pop(0)
    if bus[0] + k >= p and len(bus) < c:
        bus.append(p)
    else:
        count += 1
        bus = [p]
print(count+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
list_t = []
n,c,k = map(int, input().split())
for i in range(n):
    list_t.append(int(input()))
list_t.sort()
count = 0
j = 0
start_time = list_t[j]
start_j = j

while j < n:
    if j - start_j + 1 > c:
        count += 1
        start_j = j
        start_time = list_t[j]
        j += 1
    elif list_t[j] - k > start_time:
        count += 1
        start_j = j
        start_time = list_t[j]
        j += 1
    else:
        j += 1
print(count+1)

Submission status: Accepted

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

cnt = 0
rider = 0
limit = -1
for t in ts:
    if (rider == c) or not(t <= limit <= (t + k)):
        cnt += 1
        limit = (t + k)
        rider = 1
    else:
        rider += 1

print(cnt)

Submission status: Accepted

Solution code:
n, c, k = map(int, input().split())
t = sorted([int(input()) for _ in range(n)])
ans = 0
cnt = 0
larr = t[0]
for ti in t:
    cnt += 1
    if ti - larr > k or cnt > c:
        cnt = 1
        larr = ti
        ans += 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()
#print(T)
Bcnt = 0
i = 0
while True:
    if len(T) <= i:
        break
    BS = T[i] + K
    Bcnt += 1
    i += 1
    cnt = 1
    while cnt < C and len(T) > i:
        if T[i] <= BS:
            i += 1
            cnt += 1
        else:
            break
print(Bcnt)

Submission status: Accepted

Solution code:
N, C, K = map(int, input().split())
T = [int(input()) for i in range(N)]
T.sort()
#print(T)
Bcnt = 0
while True:
    if len(T) <= 0:
        break
    BS = T[0] + K
    Bcnt += 1
    del T[0]
    cnt = 1
    while cnt < C and len(T) > 0:
        if T[0] <= BS:
            del T[0]
            cnt += 1
        else:
            break
print(Bcnt)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
N, C, K = inpl()
T = sorted([int(input()) for _ in range(N)])
ans = 1
b, c = T[0], 1
for t in T[1:]:
    if (t > b+K) or (C <= c):
        ans += 1
        b, c = t, 1
    else:
        c += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N,C,K = inpl()
tt = [int(input()) for i in range(N)]
tt.sort()
tt.append(10**10)
ans = n = s = 0

for i in range(N):
	t = tt[i]
	if n == 0:
		s = t
	n += 1
	if n == C or tt[i+1]-s > K:
		ans += 1
		n = 0

print(ans)

Submission status: Accepted

Solution code:
n,c,k=map(int,input().split())
o=sorted(int(input()) for _ in range(n))
cnt=0
l=0
r=0

while l<n:
  while r<n and o[r]<=o[l]+k and r-l+1<=c:
    r+=1
  cnt+=1
  l=r

print(cnt)

Submission status: Accepted

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

ans = 1

earl = t[0]
count = 0
for i in range(n):
    if t[i]-earl > k or count == c:
        count = 0
        earl = t[i]
        ans += 1
    count += 1

print(ans)

Submission status: Accepted

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

t = sorted(t)
cnt_bus = 0
i = 0
while i < n:
    cnt_rider = 0
    l, r = i, min(i + c - 1, n - 1)
    while l <= r:#適当なmidを求める
        mid = (l + r) // 2
        if t[mid] > t[i] + k:
            r = mid - 1
        else:
            #t[mid] <= t[i] + k
            p = mid#最後に乗車する人の番号（仮）
            l = mid + 1

    cnt_rider = p - i + 1
    i += cnt_rider
    cnt_bus += 1
    #print(p, cnt_rider)
print(cnt_bus)

Submission status: Accepted

Solution code:
from collections import deque

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

tk = [(ti, ti+k) for ti in t]
tk.sort(key=lambda x:x[1])
tk = deque(tk)
#print(tk)


ans = 0
# tkが尽きるまで
while tk:
    _, bus = tk[0]
    
    # バスの時刻より早く来ている客をカウント
    cnt = 0
    while (tk[cnt][0] <= bus) and (cnt < c):
        cnt += 1
        
        if cnt == len(tk):
            break
        
        
    # バスの定員もしくはいる人数を乗せていく
    for _ in range(min(cnt,c)):
        tk.popleft()
    
    ans += 1
        
print(ans)

Submission status: Accepted

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

t = [0 for i in range(n)]

for i in range(n):
	t[i] = input()

t.sort()

lowest = 0
res = 1

for i in range(n):
	if i - lowest >= c:
		lowest = i
		res += 1
	elif t[i] - t[lowest] > k:
		lowest = i
		res += 1

print res

Submission status: Accepted

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


t = []
for i in range(n):
	t.append(int(input()))

t.sort()

ans = 0
depart = t[0]
people = 0

i = 0
while i < n:
	if t[i] <= depart + k and people < c :
		people += 1
		i += 1

	else :
		ans += 1
		people = 0
		depart = t[i]

print ans + 1

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


def main():
    n, c, k = list(map(int, input().split()))
    t = [0] * n

    for i in range(n):
        ti = int(input())
        t[i] = (ti, ti + k)

    sorted_t = sorted(t, key=lambda x: x[1])
    pos = sorted_t[0][1]
    remain = c - 1
    bus_count = 1

    for i in range(1, n):
        if remain >= 1 and sorted_t[i][0] <= pos:
            remain -= 1
        else:
            bus_count += 1
            pos = sorted_t[i][1]
            remain = c - 1

    print(bus_count)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


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

    remain_seats = c - 1
    departure_time = t[0] + k
    bus_count = 1

    # See:
    # https://www.youtube.com/watch?v=cJ-WjtA34GQ
    for i in range(1, n):
        if remain_seats >= 1 and t[i] <= departure_time:
            remain_seats -= 1
        else:
            bus_count += 1
            remain_seats = c - 1
            departure_time = t[i] + k

    print(bus_count)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

t = []
for i in range(n):
    t.append(int(input()))
t.sort()
a = t[0]
b = 1
ans = 1
for i in range(1,n):
    if t[i]-a <= k and b < c:
        b += 1
    else:
        ans += 1
        a = t[i]
        b = 1
print(ans)

Submission status: Accepted

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

ans = 0
passengers = 1
lasttime = T[0]
for i in range(1, N):
    if T[i] - lasttime > K:
        ans += 1
        passengers = 1
        lasttime = T[i]
    else:
        if passengers < C:
            passengers += 1
        else:
            ans += 1
            passengers = 1
            lasttime = T[i]
print(ans + 1)

Submission status: Accepted

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

T.sort()

result = 0
i = 0
j = 0
while i < N:
    if j == N or T[j] - T[i] > K:
        n = max(min(C, j - i), 1)
        if n == 0: raise
        # print(T[i:i+n], i, j)
        i += n
        result += 1
        continue
    if j >= i + C:
        # print(T[i:i+C])
        i += C
        result += 1
        continue
    j += 1

print(result)

Submission status: Accepted

Solution code:
import bisect

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

def search_next_bus(Ti):
  nxt=bisect.bisect_right(A,A[Ti]+K)
  if nxt>Ti+C:
    nxt=Ti+C
  return nxt

cnt=0
ans=0
while True:
  cnt=search_next_bus(cnt)
  ans+=1
  if cnt==N:
    break
print(ans)

Submission status: Accepted

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

ans = 1
bus_num = 1
bus_time = t[0]

for i in range(1, n):
	if t[i] > bus_time + k or bus_num == c:
		ans += 1
		bus_num = 1
		bus_time = t[i]
	else:
		bus_num += 1

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
def debug(*args): print(*args, file=sys.stderr)
def exit(): sys.exit(0)

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

T.sort()

start = 0
end = 0
count = 1
while True:
    if end >= N-1:
        break
    if (end - start + 1 >= C) or (T[end+1] > T[start] + K):
        debug(start, end)
        start = end + 1
        end = start
        if start == N:
            break
        else:
            count += 1
    else:
        end += 1

print(count)

Submission status: Accepted

Solution code:
import sys

def merge(L,R):
    res = []
    
    l_L = len(L)
    l_R = len(R)
    i = 0
    j = 0
    while (i <= l_L) & (j <= l_R):
        if (i == l_L) & (j == l_R):
            return res
        elif i == l_L:
            res.append(R[j])
            j += 1
        elif j == l_R:
            res.append(L[i])
            i += 1
        elif L[i] <= R[j]:
            res.append(L[i])
            i += 1
        else:
            res.append(R[j])
            j += 1
    return res

def divide(A):
    l_A = len(A)
    l_L = int(l_A / 2)
    l_R = l_A - l_L
    L = A[:l_L]
    R = A[l_L:]
    return L,R

def my_sort(A):
    l_A = len(A)
    if l_A == 1:
        return A
    else:
        L,R = divide(A)
        L = my_sort(L)
        R = my_sort(R)
        return merge(L,R)
    
N , C, K = map(int,input().split())
T = []
for _ in range(0,N):
    T.append(int(input()))
T = my_sort(T)

bus = 0
t_0 = T[0]
t_B = T[0] + K
num = 0


i = 0
while i < len(T):
    t = T[i]
    dt = t - t_0
    if (dt <= K) & (float((num + 1)) / float(C) <= 1):
        num += 1
    else:
        if num != 0:
            #print(T[i-1])
            bus += 1
            t_0 = t
            num = 1
    i += 1
bus += 1
print(bus)

Submission status: Accepted

Solution code:
N,C,K=map(int,input().split())
tourist=[]
for i in range (N):
    T=int(input())
    tourist.append(T)
tourist.sort()
bus_count=1
bus_tourlist=1
bus_limit=tourist[0]+K
for j in range (1,len(tourist)):
    if bus_tourlist==C or tourist[j]>bus_limit:
        bus_count+=1
        bus_limit=tourist[j]+K
        bus_tourlist=1
    
    else:
        bus_tourlist+=1
print(bus_count)

Submission status: Accepted

Solution code:
def a_airport_bus(N, C, K, T):
    import bisect
    t = sorted(T)
    index = 0  # t[index]はまだバスに乗っていない人の内最も早い空港到着時刻
    ans = 0
    while index <= N - 1:
        # 時刻 t[index] にバスを出した場合乗り込める人数の候補
        num_take_bus = bisect.bisect_right(t, t[index] + K) - index
        if num_take_bus > C:
            index += C  # 定員分だけ乗せる
        else:
            index += num_take_bus  # 乗れるだけ乗せる
        ans += 1  # バスを1台出した
    return ans

N, C, K = [int(i) for i in input().split()]
T = [int(input()) for _ in range(N)]
print(a_airport_bus(N, C, K, T))

Submission status: Accepted

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

    t_lst.sort()
    idx, bus = 0, 0
    while idx < n:
        t = t_lst[idx]
        bus += 1
        cus = 1
        idx += 1
        while idx < n and cus < c and t_lst[idx] - t <= k:
            cus += 1
            idx += 1

    print(bus)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

p = C
d = T[0]+K
ans = 1
for t in T:
    if p == 0 or t > d:
        d = t+K
        p = C-1
        ans += 1
    else:
        p -= 1

print(ans)

Submission status: Accepted

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

T = []

for i in range(N):    
    T.append(int(input()))
    
T = sorted(T)
    
start = T[0]
ans = 1
now_C = 1
for t in T[1:]:
    if t<=start+K and now_C < C:
        now_C += 1
    else:
        start = t
        ans += 1
        now_C = 1

print(ans)

Submission status: Accepted

Solution code:
n,c,k=[int(i) for i in input().split()]
a=sorted([int(input()) for i in range(n)])
b=[i+k for i in a]
i0=[]
ans=0
bi=0
for i in range(n):
  i0.append(a[i])
  l=len(i0)
  if l== c or (b[bi] < a[i] and i!=0) :
    ans+=1
    i0=[]
    bi=i
  if l != c and i==n-1:
    ans+=1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, C, K] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2])]
    T = []
    for i in range(N):
        input_raw = read_func().strip().split()
        T.append(int(input_raw[0]))
    T.sort()
    bus_count = 0
    first_time = T[0]
    people_count = 0
    for i in range(N):
        if T[i] <= first_time + K:
            people_count += 1
            if people_count >= C:
                bus_count += 1
                people_count = 0
                if i + 1 < N:
                    first_time = T[i + 1]
        else:
            bus_count += 1
            first_time = T[i]
            people_count = 1

##            if i < N - 1:
##                people_count = 1
##            else:
##                people_count = 0
    bus_count += people_count/C + (0 if people_count % C == 0 else 1)
    print bus_count



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, c, k = map(int,input().split())
take = [int(input()) for _ in range(n)]
take.sort()
ans = 1
p = take[0]
r = 1
for i in range(1, n):
    if r < c:
        if take[i] - p <= k:
            r += 1
        else:
            ans += 1
            r = 1
            p = take[i]
    else:
        ans += 1
        r = 1
        p = take[i]

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys, math, copy
# import fractions, itertools
# import numpy as np
# import scipy

HUGE = 2147483647
HUGEL = 9223372036854775807
ABC = "abcdefghijklmnopqrstuvwxyz"

def main():
    n, c, k = map(int, input().split())
    ti = []
    for i in range(n):
        t = int(input())
        ti.append(t)
    ti = sorted(ti)
    next_time = -HUGE
    next_capacity = 0
    count_bus = 0
    for t in ti:
        if (next_capacity) == 0 or (next_time < t) or (next_time > t + k):
            next_time = t + k
            next_capacity = c - 1
            count_bus += 1
        else:
            next_capacity -= 1
    print(count_bus)

main()

Submission status: Accepted

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

ans = 0
front = 0
while front < N:
    standard = T[front] + K
    front = min(bisect.bisect_right(T, standard), front+C)
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
N,C,K=map(int,input().split())
T=[int(input()) for i in range(N)]
T.sort()
S=[[T[0]]]
t=T[0]
k=0
for i in range(1,N):
    if T[i]<=t+K and len(S[k])<C:
        S[k].append(T[i])
    else:
        k+=1
        S.append([T[i]])
        t=T[i]
print(len(S))

Submission status: Accepted

Solution code:
import bisect

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

i = 0
ans = 0

while T:
    ans += 1
    check = T[0] + K
    people = bisect.bisect_right(T, check)
    if people > C:
        del T[:C]
    else:
        del T[:people]

print(ans)

Submission status: Accepted

Solution code:
n,c,k=map(int,input().split())
t=[]
for i in range(n):
  t.append(int(input()))
t.sort()
num=0
pas=0
end=-1
for i in range(n):
  if(end<t[i]):
    num+=1
    end=t[i]+k
    pas=1
    if(pas==c):
      end=-1
  else:
    pas+=1
    if(pas==c):
      end=-1
  
print(num)

Submission status: Accepted

Solution code:
import bisect

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

ans = 0
while T:
    stop = bisect.bisect_right(T, T[0]+K)
    if stop > C:
        del T[:C]
        ans += 1
    else:
        del T[:stop]
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
n,c,k = (int(i) for i in input().split())
t = [int(input()) for i in range(n)]
t.sort()
num,num2,answer = t[0]+k,0,1
for i in range(n):
	num2 += 1
	if t[i]>num or num2>c:
		num,num2=t[i]+k,1
		answer+=1
print(answer)

Submission status: Accepted

Solution code:
N, C, K = map(int, input().split())
T = []
for _ in range(N):
    T.append(int(input()))
T = sorted(T)
first = 0
C_now = C
count = 1
for t in T:
    if C_now == C:
        first = t
        C_now -= 1
    else:
        if t - first <= K:
            C_now -= 1
        else:
            count += 1
            first = t
            C_now = C-1
    if C_now == 0:
        count += 1
        C_now = C
if C_now == C:
    count -= 1
print(count)

Submission status: Accepted

Solution code:
n,c,k = map(int,input().split())
lis = []
for i in range(n):lis.append(int(input()))
lis.sort()
ans = 0
time = 0
cou = 0
for m in range(n):
    if time == 0:
        time = lis[m]
        cou += 1
    elif lis[m] <= time + k and cou < c:
        cou += 1
    else:
        ans += 1
        cou = 1
        time = lis[m]
ans += 1
print(ans)

Submission status: Accepted

Solution code:
def minimumNumberOfBus(a, c, k):
    foo = 0
    a = sorted(a)
    cur = 0
    while cur<len(a):
        departing_time = a[cur]+k
        space = c
        while space>0 and cur<len(a) and a[cur]<=departing_time:
            cur += 1
            space -= 1
        foo += 1
    return foo

def main():
    n, c, k = [int(x) for x in raw_input().strip().split()]
    a = [0 for i in xrange(n)]
    for i in xrange(n):
        a[i] = int(raw_input().strip())
    print minimumNumberOfBus(a, c, k)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
line = input().split(" ")
a = list(map(int, line))
t = []
ans = 0
for i in range(0, a[0]):
    t.append(int(input()))
t.sort()
while len(t) > 0:
    if len(t) < a[1]:
        a[1]=len(t)
    if t[0] + a[2] > t[a[1] - 1]:
        ans += 1
        del t[0:a[1]]
    else:
        for i in range(0, a[1]):
            if t[i] > t[0] + a[2]:
                del t[0:i]
                ans += 1
                break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, c, k = map(int, input().split())
t_list = []
for i in range(n):
    t = int(input())
    t_list.append(t)
t_list = sorted(t_list)
bus = 1
pas = 0
time = t_list[0]
for i in range(1, n):
    if t_list[i] - time <= k:
        pas += 1
    else:
        pas = 0
        bus += 1
        time = t_list[i]
    if pas >= c:
        pas = 0
        bus += 1
        time = t_list[i]
print(bus)

Submission status: Accepted

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

ans = dept = seat = 0
for t in src:
    if dept >= t and seat > 0:
        seat -= 1
    else:
        dept = t + K
        seat = C-1
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
n, capacity, wait = map(int, raw_input().split(' '))

v = []

for i in range(n):
	v.append(int(raw_input()))

v.sort()

last = 0
capacity_left = 0

res = 0

for i in range(n):
	if v[i] <= last and capacity_left > 0:
		capacity_left -= 1
	else:
		last = v[i] + wait
		capacity_left = capacity - 1
		res += 1
	
print res

Submission status: Accepted

Solution code:
[n,c,k] = [int(x) for x in input().split()]

xs = [int(input()) for i in range(n)]
xs.sort()

ans = 0
prv = -2e9
cnt = 0

for x in xs:
    if cnt == c or prv < x:
        cnt = 1
        prv = x + k
        ans += 1
    else:
        cnt += 1
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = float("inf")


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

    ans = 0
    left = 0
    while left < N:
        a = t_list[left] + K
        for i in range(left, min(left + C, N)):
            if t_list[i] > a:
                left = i
                break
        else:
            left += C

        ans += 1


    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def airport_bus():
	n, c, k = map(int, raw_input().split(" "))
	t = []
	for i in range(n):
		t.append(int(raw_input()))
	t.sort()
	dic_busno_sate = {}
	current_bus = 1
	for x in t:
		c_state = dic_busno_sate.get(current_bus)
		if c_state is None:
			dic_busno_sate[current_bus] = ([x, x+k], 1)
		else:
			time_range = c_state[0]
			p_num = c_state[1]
			if p_num>=c:
				current_bus+=1
				dic_busno_sate[current_bus] = ([x, x + k], 1)
			else:
				left_max = max(time_range[0], x)
				right_min = min(time_range[1], x+k)
				if left_max<=right_min:
					_p_num = p_num+1
					_time_range = [left_max, right_min]
					dic_busno_sate[current_bus] = (_time_range, _p_num)
				else:
					current_bus += 1
					dic_busno_sate[current_bus] = ([x, x + k], 1)
	print current_bus

if __name__ == "__main__":
	airport_bus()

Submission status: Accepted

Solution code:
n,c,k=map(int,input().split())
t=sorted([int(input()) for i in range(n)])
st,p,ans=-k,0,0
for i in t:
	if st+k<i or p==c:
		ans+=1
		p=1
		st=i
	else:
		p+=1
print(ans)

Submission status: Accepted

Solution code:

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

k = 0
i = 0
while i < N:
    k += 1
    c = 0
    while c < C and i + c < N and T[i + c] <= (T[i] + K):
        c += 1
    i += c
print(k)

Submission status: Accepted

Solution code:
n, c, k = map(int, raw_input().split())
t = [int(raw_input()) for _ in xrange(n)]
t.sort()
cnt = 0
check = [False] * n
for i in xrange(n):
    if check[i]:continue
    check[i] = True
    lt = t[i] + k
    for j in xrange(i, min(i + c, n)):
        if t[j] > lt :break
        check[j] = True
    cnt += 1
print cnt

Submission status: Accepted

Solution code:
n,c,k = map(int, raw_input().split())
l = [int(raw_input()) for _ in range(n)]
l.sort()
cnt = 1
p = 0
for i,t in enumerate(l):
    if i-p >= c or l[p] + k < t:
        cnt += 1
        p = i
print cnt

Submission status: Accepted

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

res = 1
start = arr[0]
cur = c

for pas in arr:
	if c == 0:
		c = cur - 1
		start = pas
		res += 1
		continue

	if pas <= start + k:
		c -= 1
	else:
		res += 1
		c = cur -1
		start = pas

print res

Submission status: Accepted

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

res = 1
start = arr[0]
cur = c

for pas in arr:
	if c == 0:
		c = cur
		start = pas
		res += 1

	if pas <= start + k:
		c -= 1
	else:
		res += 1
		c = cur -1
		start = pas

print res

Submission status: Accepted

Solution code:
n, c, k = map(int, input().split())
arrivals = [int(input()) for i in range(n)]
arrivals.sort()
 
res = 0
room = c
bus_start = None
 
for t in arrivals:
 
    previous_bus_has_left = bus_start is not None and bus_start + k < t
    if previous_bus_has_left:
        res += 1
        room = c
 
    if room == c:
        bus_start = t
 
    room -= 1
 
    if room == 0:
        res += 1
        room = c
        bus_start = None
 
if room < c:
    res += 1
 
print(res)

Submission status: Accepted

Solution code:
N,C,K = map(int, raw_input().split(" "))
timelist = []
for i in range(0, N):
    timelist.append(int(raw_input()))
timelist.sort()


class Foo:

    timelist = []
    buslist = []
    firstId = 0
    capacity = 0

    def __init__(self, timelist):
        self.timelist = timelist

    def addBus(self, i):
        self.buslist.append(self.timelist[i])
        self.firstId  = i + 1
        self.capacity = 0

    def calc(self):
        for i in range(0, N):

            if i == N - 1:
                self.addBus(i)
                break

            nexttime = self.timelist[i + 1]

            self.capacity += 1
            # timeover
            if nexttime > timelist[self.firstId] + K:
                self.addBus(i)
                continue

            # capacity over
            if self.capacity >= C:
                self.addBus(i)
                continue


    def printBusList(self):
        for bus in self.buslist:
            print(bus)

    def printTotalBusNum(self):
        print(len(self.buslist))


foo = Foo(timelist)
foo.calc()
foo.printTotalBusNum()

Submission status: Accepted

Solution code:
def numBuses(people, cap, wait):
	buses = 0
	currentCap = 0
	departTime = -1
	for person in people:
		if departTime == -1 or currentCap == cap or departTime - person > wait:
			departTime = person
			buses += 1
			currentCap = 1
		else:
			currentCap += 1
	return buses

[n, cap, wait] = list(map(lambda x: int(x), input().split()))
people = []
for i in range(n):
	people.append(int(input()))
print(numBuses(sorted(people, reverse=True), cap, wait))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

idx = 0
bus = 0
while(True):
    if idx == N:
        break
    bus += 1
    limit = T[idx] + K
    for c in range(idx,idx+C):
        if idx == N:
            break
        dep = T[c]
        if dep <= limit:
            idx += 1
            continue
        else:
            break
print(bus)

Submission status: Accepted

Solution code:
n, c, k = map(int, input().split())
q = sorted([int(input()) for i in range(n)])
ans = 1
f = q.pop(0)
p = 1
for i in q:
    if i > f + k or p >= c:
        ans += 1
        f = i
        p = 1
    else:
        p += 1
print(ans)

Submission status: Accepted

Solution code:
arg = input().split(' ')
n = int(arg[0])
c = int(arg[1])
k = int(arg[2])
t = []
for i in range(n):
  t.append(int(input()))
t.sort()

res = 1
first = t[0]
pas = 0

for ti in t:
  if ti <= first + k:
    if pas == c:
      res += 1
      first = ti
      pas = 0
    pas += 1
  else:
    res += 1
    first = ti
    pas = 1

print(res)

Submission status: Accepted

Solution code:
#AGC011A

n,c,k=map(int,raw_input().split())
ll=[]
for i in xrange(n):
 temp=int(raw_input())
 ll.append(temp)
l=sorted(ll)

cnt=0
i=0
r=0
while i<n:
 if l[i]-l[r]>k:
  cnt+=1
  r=i
  i+=1
 elif i-r>=c:
  cnt+=1
  r=i
  i+=1
 else:
  i+=1

print cnt+1