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:
def resolve():
    '''
    code here
    '''
    N, C, K = [int(item) for item in input().split()]
    Ts = [int(input()) for _ in range(N)]
    Ts.sort()

    res = 0
    temp_psg = 0
    lim = Ts[0] + K

    for i in range(N):
        temp_psg += 1
        if Ts[i] > lim:
            res += 1
            temp_psg = 1
            lim = Ts[i] + K
        else:
            if temp_psg == C and i < N-1:
                res += 1
                temp_psg = 0
                lim = Ts[i+1] + K
        # print(Ts[i], temp_psg, res, lim)
    
    if temp_psg > 0:
        res += 1
    print(res)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    n, c, k = [int(x) for x in input().split()]
    a = []
    for _ in range(n):
        a.append(int(input()))
    a.sort()
    ans = 0
    bus = 0
    deadline = 0
    for t in a:
        if t <= deadline and bus < c:
            bus += 1
        else:
            bus = 1
            ans += 1
            deadline = t + k
    print(ans)



t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

abc

"""

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[11]:


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


# In[13]:


T = sorted(T)
ans = 0
p = 0
t = 0
for i in range(N):
    if t == 0:
        t = T[i]
    if T[i] <= t+K:
        p += 1
        if p >= C:
            ans += 1
            p = 0
            t = 0
    else:
        t = T[i]
        ans += 1
        p = 1
if p > 0:
    ans += 1
print(ans)


# In[ ]:

Submission status: Accepted

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# 約数生成
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

n,c,k = lr()
t = [ir() for i in range(n)]
t.sort()
ans = 0
count = 0
ind = 0
while ind < n:
    now = t[ind]
    while ind < n and t[ind] <= now+k and count < c:
        ind+=1
        count+=1
    ans+=1
    count=0
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
enum = enumerate

def linput(ty=int, cvt=list):
	return cvt(map(ty,input().split()))

def vinput(rep=1, ty=int, cvt=list):
	return cvt(ty(input().rstrip()) for _ in "*"*rep)

def gcd(a: int, b: int):
	while b: a, b = b, a%b
	return a

def lcm(a: int, b: int):
	return a * b // gcd(a, b)

def main():
	N,C,K = linput()
	vA = vinput(N)
	vA.sort()
	#vA.reverse()
	
	res = 0
	#i = 0   #..N
	cnt = 0 #..C
	x = 0   #(T-x)..K
	
	for a in vA:
		if a<=x and cnt<C:
			cnt += 1
			continue
		cnt = 1
		res += 1
		x = a+K
	
	#sT = "No Yes".split()
	#print(sT[res])
	print(res)

if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
enum = enumerate

def linput(ty=int, cvt=list):
	return cvt(map(ty,input().split()))

def vinput(rep=1, ty=int, cvt=list):
	return cvt(ty(input().rstrip()) for _ in "*"*rep)

def gcd(a: int, b: int):
	while b: a, b = b, a%b
	return a

def lcm(a: int, b: int):
	return a * b // gcd(a, b)

def main():
	N,C,K = linput()
	vA = vinput(N)
	vA.sort()
	#vA.reverse()
	
	res = 0
	i = 0   #..N
	cnt = 0 #..C
	x = 0   #(T-x)..K
	while i<len(vA):
		if not cnt:
			cnt += 1
			x = vA[i]+K
			i += 1
			res += 1
		elif cnt<C:
			if vA[i]<=x:
				cnt += 1
				i += 1
			else:
				cnt = 1
				x = vA[i]+K
				res += 1
				i += 1
		else:
			cnt = 1
			x = vA[i]+K
			res += 1
			i += 1
	
	#sT = "No Yes".split()
	#print(sT[res])
	print(res)

if __name__ == "__main__":
	main()

Submission status: Accepted

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


from collections import deque

T = deque(sorted(T))

t_ref = T[0]

bus = 0
member = 0

while T != deque([]):
    t = T[0]
    if t - t_ref <= K and member < C:
        member += 1
        t_tmp = T.popleft()
#        print(t_tmp, 'ok')
#        print(member)
    else:
        bus += 1
        member = 0
        t_ref = T[0]
#        print()
#        print(t_ref, 'new')
if member > 0:
    bus += 1
#print()
print(bus)

Submission status: Accepted

Solution code:
import sys,bisect,math
input = sys.stdin.readline

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

n = 0
cnt = 0
while n < N:
    target = T[n]+K
    nb = n
    n = bisect.bisect_right(T,target)
    if n - nb > C:
        n = nb + C
    cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
N, C, K = map(int, input().split())
t_li = []
for _ in range(N):
    t_li.append(int(input()))
t_li.sort()
# 最初にバスに乗る乗客の到着時間
first = t_li[0]
# バス1台に乗ってる乗客。最初の一人を載せておく
passengers = 1
# バスの台数。N >= 2なので少なくとも1台は必要
busses = 1
# 二人目から数えていく
for i in range(1, N):
    if passengers < C and t_li[i] - first <= K:
        # 搭乗員数と時間に余裕があるなら、同じバスに乗せていく
        passengers += 1
    else:
        # 次のバスを用意する
        busses += 1
        passengers = 1
        first = t_li[i]
print(busses)

Submission status: Accepted

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

T.sort()

ans = 0
p = C
d_time = 0

for i in range(N):
    if T[i] - d_time > K or p == C:
        ans += 1
        d_time = T[i]
        p = 1
    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)])

total = 1
s_time = T[0]
count = 1
for i in range(1, N):
    count += 1
    if s_time + K < T[i] or count > C:
        s_time = T[i]
        count = 1
        total += 1
print(total)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n, c, k = map(int, input().split())
a = sorted([int(input()) for i in range(n)])

ans = 0
busp = 0
machi = 0

for i in a:
    if busp == 0:
        busp += 1
        machi = i + k
        if busp >= c:
            ans += 1
            busp = 0
            machi = 0

    elif i <= machi:
        busp += 1
        if busp >= c:
            ans += 1
            busp = 0
            machi = 0

    elif i > machi:
        ans += 1
        busp = 1
        machi = i + k

if busp >= 1:
    ans += 1

print(ans)

Submission status: Accepted

Solution code:
from collections import deque


N, C, K = map(int, input().split())
T = [int(input()) for _ in range(N)]
T.sort()
d = deque(T)
count = 0
while len(d) > 0:
    t = d.popleft() + K
    for i in range(C-1):
        if len(d) > 0 and d[0] <= t:
            d.popleft()
        else:
            break
    count += 1

print(count)

Submission status: Accepted

Solution code:
n, c, k=map(int,input().split())
bus=1
pssgr=0
fst_pssgr=0
t_lst=[]
for i in range(n):
    t=int(input())
    t_lst.append(t)

t_lst.sort()

for i in range(n):
    if t_lst[i]-t_lst[fst_pssgr]>k:
        bus+=1
        pssgr=1
        fst_pssgr=i
        continue
    pssgr+=1
    if pssgr==c and i<n-1:
        bus+=1
        pssgr=0
        fst_pssgr=i+1

print(bus)

Submission status: Accepted

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

import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)
MOD = pow(10, 9) + 7

N, C, K, *T = map(int, read().split())
T.sort()

acc = 0
n_bus = 0
cnt = 0
for t in T:
    if cnt == 0:
        acc = t + .5
        n_bus += 1
        cnt = 1
        if cnt == C:
            cnt = 0
        continue

    if t - acc <= K:
        cnt += 1
    else:
        cnt = 1
        acc = t + .5
        n_bus += 1
        continue
    if cnt == C:
        cnt = 0

print(n_bus)

Submission status: Accepted

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

T = []

for i in range(N):
    T.append(int(input()))
T.sort()
res = 0
cnt = 0
i = 0

while i < N:
    lim = T[i]+K
    while T[i] <= lim and cnt < C:
        i += 1
        cnt += 1
        if N == i:
            break
    res += 1
    cnt = 0
print(res)

Submission status: Accepted

Solution code:
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n, c, k = MI()
    T = sorted([I() for _ in range(n)])
    cnt = 0
    i = 0
    while i < n:
        cnt += 1
        lim = T[i] + k
        cap = 1
        for j in range(i+1, min(n, i+c)):
            if T[j] <= lim:
                cap += 1
            else:
                break
        i += cap
    print(cnt)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = 1
now = t[0]
cnt = 0
for i in t:
    cnt += 1
    if i > now + k or cnt > c:
        ans += 1
        cnt = 1
        now = i

print(ans)

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

n,c,k = list(map(int, input().split()))
ts = [None]*n
for i in range(n):
    ts[i] = int(input())
ts.sort()
ans = 0
last = -float("inf")
num = 0
for t in ts:
    if last<t or num==c:
        last = t+k
        num = 1
        ans += 1
    else:
        num += 1
print(ans)

Submission status: Accepted

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

limit = t[0] + k
num = 1
cnt = 1
for i in range(1, n):
  if limit < t[i] or num == c:
    num = 1
    limit = t[i] + k
    cnt += 1
  
  else:
    num += 1
print(cnt)

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0

N, C, K =I()
T = []
for i in range(N):
    t = k()
    T.append(t)

T.sort()
a = T[0]+K
pas = 0
ans = 1

for i in range(N):
    if pas == C or a < T[i]:
        pas = 1
        ans += 1
        a = T[i]+K
    else:
        pas += 1

print(ans)

Submission status: Accepted

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

t.sort()
ans=1
pas=0
depa=t[0]+k

for i in range(n):
  if c==pas or depa<t[i]:
    ans+=1
    pas=1
    depa=t[i]+k
  else:
    pas+=1
print(ans)

Submission status: Accepted

Solution code:
import bisect,copy,heapq,itertools,string
from collections import *
from math import *
import sys
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n, c, k = MAP()
t = sorted(list(INT() for i in range(n)))

ans = 0
num = 0
time = inf
for i in range(n):
        if t[i]<=time+k and num < c:
                num += 1
        elif t[i]>time+k or num == c:
                ans += 1
                num = 1
                time = inf
        time = min(time, t[i])
ans += 1
print(ans)

Submission status: Accepted

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

n, c, k = [int(w) for w in input().split()]
la = [int(input()) for _ in range(n)]
la.sort()
lak = [a + k for a in la]

ind = 0
ans = 0
while ind < n:
    ride = bisect.bisect_right(la, lak[ind]) - ind
    ind += min(ride, c)
    ans += 1

print(ans)

Submission status: Accepted

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

a.sort()
ans = 1
count = 0
pre = a[0]
for i in range(N):
    if count == 0:
        pre = a[i]
    if count >= C or a[i]-pre > K:
        count = 0
        ans += 1
        pre = a[i]
    count += 1
print(ans)

Submission status: Accepted

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

T = sorted([int(input()) for _ in range(N)])
ans = 1
count = 0
time = 0
start = -1
for i in range(N):
  if start == -1:
    start = i
  if i != N-1:
    if T[i+1] > T[start] + K or i+1 -start == C:
      ans += 1
      start = -1
  
print(ans)

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, s, m = 0, 0, 0
 
for t in T:
    if m == 0:
        s = t
        m = 1
        ans += 1
    else:
        if t <= s + k:  # kill me now
            m += 1
        else:
            s = t
            m = 1
            ans += 1
    if m == c:
        m = 0
 
print(ans)

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, s, m = 0, 0, 0

for t in T:
    if m == 0:
        s = t
        m = 1
        ans += 1
    else:
        if t <= s + k:
            m += 1
        else:
            s = t
            m = 1
            ans += 1
    if m == c:
        m = 0
 
print(ans)

Submission status: Accepted

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

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')
from math import *


def main():
	n,c,k=MI()
	T=[II() for _ in range(n)]
	T.sort()
	#print(T)
	
	ans=0
	cnt=0
	now=0
	
	i=0
	
	while i<n:
		#print(i)
		now=T[i]
		ans+=1
		cnt=1
		while i<n and cnt<=c and now+k>=T[i]:
			i+=1
			cnt+=1
		cnt=0
	
	print(ans)
	
	
	
	
	


	
if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
import sys
N, C, K = map(int, input().split())
A = list(map(int, sys.stdin.readlines()))+[10**10]
A.sort()
a, c, t = 0, 1, A[0]+K
for i in A[1:]:
    if i <= t and c < C:
        c += 1
    else:
        t, c = i + K, 1
        a += 1
 
print(a)

Submission status: Accepted

Solution code:
n, c, k = map(int, input().split())
l = [int(input()) for _ in range(n)]
l = sorted(l)
val, ans = l[0], 1
count = 1
for i in l[1:]:
    count += 1
    if i-val > k or count > c:
        ans += 1
        count, val = 1, i
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, C, K = map(int, input().split())
T = [0 for _ in range(N)]
for __ in range(N):
    T[__] = int(input())
 
T.sort()
bus_count = 1
bus_rest = C
bus_depert = T[0]+K
 
for ix in range(N):
 
    if T[ix] <= bus_depert and bus_rest > 0:
        bus_rest -= 1
 
    else:
        bus_count += 1
        bus_depert = T[ix] + K
        bus_rest = C - 1
 
print(bus_count)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N, C, K = [int(x) for x in input().split()]
T = [int(input()) for _ in range(N)]
T.sort()
depart = T[0] + K  # 出発時刻
passenger = 0  # 乗客数
bus = 1
for i in range(N):
    if passenger >= C or depart < T[i]:  # すでに満員または待ち時間オーバー
        bus += 1
        passenger = 1
        depart = T[i] + K
    else:
        passenger += 1

print(bus)

Submission status: Accepted

Solution code:
N, C, K = [int(x) for x in input().split()]
T = [int(input()) for _ in range(N)]
T.sort()
depart = T[0] + K  # 出発時刻
passenger = 0  # 乗客数
bus = 1
for i in range(N):
    if passenger >= C or depart < T[i]:  # すでに満員または待ち時間オーバー
        bus += 1
        passenger = 1
        depart = T[i] + K
    else:
        passenger += 1

print(bus)

Submission status: Accepted

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

in_bus = 0
first = 0
last = 0
bus_count = 0
for i in range(N):
    if (i == 0):
        first = T[i]
        last = T[i] + K
        in_bus += 1
        bus_count += 1
        continue

    if (in_bus == C):
        bus_count += 1
        in_bus = 1
        first = T[i]
        last = T[i] + K
        continue

    if (T[i] >= first and last >= T[i]):
        in_bus += 1
    else:
        first = T[i]
        last = T[i] + K
        in_bus = 1
        bus_count += 1


print(bus_count)

Submission status: Accepted

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

T.sort()
bus_count = 1
bus_rest = C
bus_depert = T[0]+K

for ix in range(N):

    if T[ix] <= bus_depert and bus_rest > 0:
        bus_rest -= 1

    else:
        bus_count += 1
        bus_depert = T[ix] + K
        bus_rest = C - 1

print(bus_count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
n, c, k = map(int, input().split())
time_people = Counter([int(input()) for _ in range(n)])
times = sorted(time_people.keys())
ans = 0
left = 0
right = 0
while time_people[times[-1]] > 0:
    space = c
    while times[left] + k >= times[right] and space > 0:
        new_passenger = min(c, time_people[times[right]])
        space -= new_passenger
        time_people[times[right]] -= new_passenger
        if right >= len(times):
            break
        if time_people[times[right]] == 0:
            right += 1
            if right == len(times):
                break
    ans += 1
    while left < len(times) and time_people[times[left]] <= 0:
        left += 1
print(ans)

Submission status: Accepted

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

bus = 0
pa = 1
S = T[0]

for i in T[1:]:
    pa += 1
    if K < i-S or pa > C:
        bus += 1
        pa = 1
        S = i
print(bus+1)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/agc011/tasks/agc011_a
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def read_a_int(): return int(read())


def read_ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


N, C, K = read_ints()
T, = read_col(N)
T.sort()

# 条件が2つのgreedy
# つまりsorted(T)に対して、C人乗ったら出発。K分経ったら出発を繰り返す。
bus = []  # バスの乗客
ans = 0  # なんかいバスが出発したか
for t in T:
    if (len(bus) and bus[0] + K < t) or len(bus) == C:  # これ以上待てないor C人になった
        ans += 1  # バスを出発させる
        # print(bus)
        bus = []
    bus.append(t)
if bus:
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
N,C,K = map(int, input().split())
L = []
for a in range(N):
  L.append(int(input()))
L.sort()
L.append(10**10)
x = 0
y = 0
z = L[0]
for i in range (N+1):
  if y < C and z+K >= L[i]:
    y += 1
  else:
    x += 1
    y = 1
    z = L[i]    
print(x)

Submission status: Accepted

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

ans = 0
x = 0
capacity = 0
for L, R in times:
    if L <= x:
        if c == capacity:
            capacity = 1
            ans += 1
            x = R
        else:
            capacity += 1
    else:
        x = R
        ans += 1
        capacity = 1
print(ans)

Submission status: Accepted

Solution code:
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

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

    t.sort()
    t0 = t[0]
    n = 1
    ans = 0
    for i in t[1::]:
        if n == c or i > k+t0:
            ans += 1
            n = 1
            t0 = i
        else:
            n += 1
    ans += 1
    print(ans)

    return

if __name__ == '__main__':
    main()

Submission status: Accepted

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

lmt = 0
flg = True
tmp_c = c
bus_cnt = 0
for i in range(len(T)-1):
    if flg:
        lmt = T[i] + k
        flg = False
        bus_cnt += 1
    if tmp_c >= 0 or lmt >= T[i]:
        tmp_c -= 1
    if tmp_c <= 0 or lmt < T[i+1]:
        flg = True
        tmp_c = c
else:
    if tmp_c <= 0 or lmt < T[-1]:
        bus_cnt += 1

print(bus_cnt)

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

N,C,K = I()
T = [i() for _ in range(N)]
T.sort()
T = deque(T)
ans = [[] for _ in range(N)]
ans[0].append(T.popleft())
now = 0
while T:
    a = T.popleft()
    if len(ans[now]) == C or a-ans[now][0] > K:
        now += 1
    ans[now].append(a)
print(now+1)

Submission status: Accepted

Solution code:
n,c,k=map(int,input().split())
t=[int(input()) for _ in range(n)]
t.sort()
cnt,now=0,0
while now<n:
    temp=t[now]+k
    a=now
    for i in range(c-1):
        if i+1+a>=n:
            break
        if t[i+1+a]>temp:
            break
        now+=1
    now+=1
    cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
import sys
n, c, k = map(int, input().split())
a = list(map(int, sys.stdin.readlines()))+[10**10]
a.sort()
ans, cnt, tmp = 0, 1, a[0]+k
for i in a[1:]:
    if i <= tmp and cnt < c:
        cnt += 1
    else:
        tmp, cnt = i + k, 1
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
import bisect

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

T = [0]*N
for i in range(N):
    T[i] = int(input())
T.sort()


#print(T)

ans = 0
left = 0
while True:
    if left >= N:
        break
    #print("T[left]",T[left])
    ind = bisect.bisect_right(T, T[left]+K)
    #print("ind",ind)
    left = min(ind, left+C)
    ans += 1
    #print("left",left)
    #print('&&&&&&&&&&&&&&&&&&')
    
print(ans)

Submission status: Accepted

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

def main():
    n, c, k = input_list()
    arrivals = []
    for _ in range(n):
        arrivals.append(int(input()))
    arrivals.sort()
    count = 0
    limit = 0
    ans = 0
    for i, a in enumerate(arrivals):
        if limit and limit < a:
            limit = 0
            count = 0
            ans += 1
        if not limit:
            limit = a + k
        if a <= limit:
            count += 1
        if count == c:
            ans += 1
            count = 0
            limit = 0
    if count > 0:
        ans += 1
    print(ans)

def input_list():
    return list(map(int, input().split()))


def input_list_str():
    return list(map(str, input().split()))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, C, K, *T = map(int, read().split())
T.sort()

def main(N, C, K, T):
    INF = K + 100
    time = -INF
    people = 0
    bus = 0
    for t in T:
        if t > time + K:
            time = t
            people = 1
            bus += 1
            continue
        if people < C:
            # 乗れる
            people += 1
        else:
            # 乗れない
            time = t
            people = 1
            bus += 1
    return bus

print(main(N, C, K, T))

Submission status: Accepted

Solution code:
N, C, K=map(int, input().split())
X=[]
for _ in range(N):
  X.append(int(input()))
X.sort()
X.append(10**19)
ans=0
tamatta=0
hayaihito=X[0]
for i in range(N+1):
  if tamatta<C and hayaihito+K>=X[i]:
    tamatta+=1
  else:
    ans+=1
    tamatta=1
    hayaihito=X[i]
    
print(ans)

Submission status: Accepted

Solution code:
n, c, k, *T = map(int, open(0).read().split())
T.sort()
ans = s = 0
while s < n:
    t = T[s] + k
    X = [T[s]]
    for i in range(s+1, min(n, s+c)):
        if T[i] <= t:
            X.append(T[i])
        else:
            break
    s += len(X)
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin python3
# -*- coding: utf-8 -*-

from bisect import bisect_left, bisect_right

def main():
    N,C,K = map(int, input().split())
    Ti = list(int(input()) for _ in range(N))
    Ti.sort()
    i = 0
    ret = 0
    while i<N:
        ret += 1
        s = i
        Ts = Ti[i]
        while i<N and Ti[i]<=(Ts+K) and (i-s)<C:
            i += 1

    print(ret)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

lt = list()
for i in range(n):
    lt.append(int(input()))
lt.sort()

b = 1  #the number of buses
p = 0  #passengers
m = lt[0]

for i in range(n):
    if p < c and lt[i]-m <= k:
        p += 1
    else:
        p = 1
        b += 1
        m = lt[i]

print(b)

Submission status: Accepted

Solution code:
n_people,bus_capacity,can_wait = map(int,input().split())
arriving_time_ls = [0] * n_people
for i in range(n_people):
    arriving_time_ls[i] = int(input())
arriving_time_ls.sort()

waiting_last = 0
bus_count = 0
for i in range(1,n_people):
    if (arriving_time_ls[i] - arriving_time_ls[waiting_last] > can_wait) or (i - waiting_last + 1 > bus_capacity):
        bus_count += 1
        waiting_last = i
bus_count += 1
print(bus_count)

Submission status: Accepted

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

bus = 0
pas = 0
l = 0
r = 0
while l < N:
    if r == N:
        if pas == 0:
            break
        else:
            bus += 1
            break
    elif T[l] + K >= T[r]:
        pas += 1
        r += 1
        if pas == C:
            bus += 1
            l = r
            pas = 0
    else:
        l = r
        bus += 1
        pas = 0
print(bus)