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: Time Limit Exceeded

Solution code:
import math
import queue
from collections import defaultdict
 
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def printQueue(q):
	r=qb
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
def dq():
	return queue.deque()
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		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 -1*self.parents[self.find(x)]

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

	def members(self,x): # much time
		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()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1

n,c,k = readInts()
t = []
for i in range(n):
	t.append(readInt())
t.sort()

def people(n):
	ans = 0
	for i in t:
		if n>=i:
			ans+=1
		else:
			break
	#print(n,t,ans)
	return ans

ans = 0
while len(t)>0:
	pi = t[0]
	mens = people(pi+k)
	bus = mens//c
	if bus!=0:
		ans+=bus
		t = t[bus*c:]
	else:
		ans+=1
		t = t[mens:]

	#print(pi,mens,bus,t)
print(ans)

Submission status: Time Limit Exceeded

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
    while True:
        flg = True
        for i, ti in enumerate(t):
            if ti - t[0] > k:
                t = t[i:]
                flg = False
                break
            elif i + 1 >= c:
                t = t[i + 1:]
                flg = False
                break

        ans += 1

        if flg or len(t) == 0:
            break

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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
    while True:
        for i, ti in enumerate(t):
            if ti-t[0] > k:
                t = t[i:]
                break
            elif i+1 >= c:
                t = t[i+1:]
                break

        ans += 1

        if len(t) == 0 or i == len(t) - 1:
            break

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N, C, K = map(int,input().split())
T = [int(input()) for i in range(N)]
T.sort()
counter = 0
i = 0
while i<N:
    for j in range(C):
        if i+(C-j-1)<N and T[i]+K >= T[i+(C-j-1)]:
            counter += 1
            i = i+(C-j-1)+1
            break
print(counter)

Submission status: Time Limit Exceeded

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

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

T.sort()

num_track = 0
i = 0
while i < N:
	L = T[i]
	if i + C + 1 < N:
		kouho = T[i:i+C] # T[i],...,T[i+C-1]
	else:
		kouho = T[i:]
	# <= L + K
	num = 0
	for j in range(len(kouho)):
		if kouho[j] - L <= K:
			num += 1
	num_track += 1
	i += num

print(num_track)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n, c, k, *t = map(int, open(0).read().split())
    t = sorted(t)
    u = tuple(t)

    count = 0
    i = 0
    while i < n:
        x = u[i] + k
        y = min(i + c - 1, n - 1)
        while True:
            if u[y] <= x:
                break
            y -= 1

        count += 1
        i = y + 1

    print(count)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n, c, k, *t = map(int, open(0).read().split())
    t = sorted(t)

    count = 0
    i = 0
    while i < n:
        x = t[i] + k
        y = min(i + c - 1, n - 1)
        while True:
            if t[y] <= x:
                break
            y -= 1

        count += 1
        i = y + 1

    print(count)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n,c,k=map(int,input().split())
t=[int(input()) for _ in range(n)]+[10**10]
t.sort()
b=1
p=0
while p<n:
  l=t[p]+k
  pp=1
  f=1
  while pp<c and f:
    p+=1
    if t[p]<=l:
      pp+=1
      if pp==c:
        p+=1
    else:
      f=0
  if p<n:
    b+=1
print(b)

Submission status: Time Limit Exceeded

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

users = sorted(users, reverse=False)

ans = 0
pos = 0
start = 0

while True:
    count = 0

    if pos == N:
        break
        
    start = users[pos]
#     print("start:{}".format(start))
    for i in range(C):
        if pos+i < N and users[pos+i] <= start+K:
            count += 1
    pos += count
#     print("pos:{}".format(pos))
    ans += 1
#     print("ans:{}".format(ans))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def boundary_find(array, limit):
    ceil = len(array) - 1 
    floor = 0
    while 1:
        center = (ceil + floor) // 2
        if array[center] <= limit:
            floor = center
        else:
            ceil = center
        if ceil - floor == 1:
            break
    return ceil

n, c, k = map(int, input().split())
tList = [int(input()) for _ in range(n)]
tList.sort()
count = 0
while 1:
    limit = tList[0] + k
    last = min(c, len(tList))
    if tList[last - 1] <= limit:
        mark = last
    else:
        mark = boundary_find(tList, limit)
    count += 1
    tList = tList[mark:]
    if tList == []:
        break
print(count)

Submission status: Time Limit Exceeded

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


#----------
N,C,K = list(map(int, input().rstrip().split()))

T_list = [int(input().strip()) for _ in range(N)]
T_list.sort()

#----------
num_bus=0
i=0
while i < len(T_list):

    # Busに何人乗せられるか時刻を比較
    member_bus=0
    break_flg=False
    for j in range(C):
        if (i+j) < len(T_list):
            if T_list[i+j] <= (T_list[i] + K):
                member_bus += 1

    num_bus += 1
    i = i + member_bus
            

print(num_bus)

Submission status: Time Limit Exceeded

Solution code:
def boundary_find(array, limit):
    while 1:
        center = len(array) // 2
        if array[center] <= limit:
            array = array[center:]
        else:
            array = array[:center]
        if len(array) == 1:
            break
    return array[0]

n, c, k = map(int, input().split())
tList = [int(input()) for _ in range(n)]
tList.sort()
count = 0
while 1:
    limit = tList[0] + k
    last = min(c, len(tList))
    if tList[last - 1] <= limit:
        mark = last - 1
    else:
        mark = tList.index(boundary_find(tList, limit))
    count += 1
    tList = tList[mark + 1:]
    if tList == []:
        break
print(count)

Submission status: Time Limit Exceeded

Solution code:
n, c, k = map(int, input().split())
tList = [int(input()) for _ in range(n)]
tList.sort()
count = 0
while 1:
    limit = tList[0] + k
    last = min(c, len(tList))
    if tList[last - 1] <= limit:
        mark = last - 1
    else:
        for i in range(last):
            if tList[i] > limit:
                break
            mark = i
    count += 1
    tList = tList[mark + 1:]
    if tList == []:
        break
print(count)

Submission status: Time Limit Exceeded

Solution code:
n, c, k = map(int, input().split())
tList = [int(input()) for _ in range(n)]
tList.sort()
count = 0
while 1:
    limit = tList[0] + k
    for i in range(min(c, len(tList))):
        mark = i
        if tList[i] > limit:
            mark -= 1
            break
    count += 1
    tList = tList[mark + 1:]
    if tList == []:
        break
print(count)

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    N, C, K = map(int, input().split())
    T = [int(input()) for _ in range(N)]
    T.sort()
    count_bus = 0
    L = len(T)

    i = 0
    while i < L:
        # print('T[{}]: {}'.format(i, T[i]))
        t = T[i]
        for j in range(1, C):
            if i+j >= L:
                i += j
                count_bus += 1
                break

            if T[i+j] <= t + K:
                pass
                if j == C-1:
                    i += j + 1
                    count_bus += 1
                    break

            else:
                count_bus += 1
                i += j
                break

    print(count_bus)


if __name__ == '__main__':
    resolve()

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    N, C, K = map(int, input().split())
    T = [int(input()) for _ in range(N)]
    T.sort()
    
    count_bus = 0
    
    i = 0
    while i < len(T):
        # print('T[{}]: {}'.format(i, T[i]))
        t = T[i]
        for j in range(1, C):
            if i+j >= len(T):
                i += j
                count_bus += 1
                break
    
            if T[i+j] <= t + K:
                pass
                if j == C-1:
                    i += j + 1
                    count_bus += 1
                    break
    
            else:
                count_bus += 1
                i += j
                break
    
    print(count_bus)


if __name__ == '__main__':
    resolve()

Submission status: Time Limit Exceeded

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

i = 0
while i < len(T):
    t = T[i]
    for j in range(1, C):
        if i+j >= len(T):
            i += j
            count_bus += 1
            break
        if T[i+j] <= t + K:
            pass
            if j == C-1:
                i += j + 1
                count_bus += 1
                break
        else:
            count_bus += 1
            i += j
            break

print(count_bus)

Submission status: Time Limit Exceeded

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

passengers = sorted([int(input()) for i in range(N)])
res = {}

for p in passengers:
    key = False
    for k in res.keys():
        if k <= p and p <= k + K and res[k] <= C - 1:
            res[k] += 1
            key = True
            break
    if not key:
        res[p] = 1
print(len(res))

Submission status: Time Limit Exceeded

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

passengers = sorted([int(input()) for i in range(N)])
res = {}
key = False
for p in passengers:
    #    if len(res):
    #        res[p] = 1
    for k, val in res.items():
        if k <= p and p <= k + K and val <= C - 1:
            res[k] += 1
            key = True
            break
    if not key:
        res[p] = 1
    else:
        key = False
print(len(res))

Submission status: Time Limit Exceeded

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

listT.sort()

def func(listT,bus):
    if len(listT)==0:
        print(bus)
        sys.exit()
    elif len(listT)<C:
        for j in range(1, len(listT)):
            if listT[j]-listT[0]>K:
                bus += 1
                return func(listT[j:],bus)
        bus += 1
        print(bus)
        sys.exit()

    elif len(listT)>=C:
        for i in range(1,C):

            if listT[i]-listT[0]>K:
                bus += 1
                return func(listT[i:],bus)

        bus += 1
        return func(listT[C:],bus)

func(listT,0)

Submission status: Time Limit Exceeded

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

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

while T:
    n = min(C - 1, len(T) - 1)
    if T[n] <= T[0] + K:
        n = C
    else:
        n = bisect_right(T, T[0] + K)
    T = T[n:]
    answer += 1

print(answer)

Submission status: Time Limit Exceeded

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

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

while T:
    n = min(C, bisect_right(T, T[0] + K))
    T = T[n:]
    answer += 1

print(answer)

Submission status: Time Limit Exceeded

Solution code:
import bisect


def resolve():
    n, c, k = map(int, input().split())
    t = list(int(input()) for _ in range(n))
    t.sort()
    ans = 0
    while t:
        candidates = bisect.bisect_left(t, t[0] + k)
        # candidates = len([tj for tj in t if tj <= t[0] + k])
        num = min(c, candidates)
        t = t[num:]
        ans += 1
    print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    n, c, k = map(int, input().split())
    t = list(int(input()) for _ in range(n))
    t.sort()
    ans = 0
    while t:
        candidates = len([tj for tj in t if tj <= t[0] + k])
        num = min(c, candidates)
        t = t[num:]
        ans += 1
    print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

Solution code:
n, c, k = map(int, input().split())
l = sorted([int(input()) for i in range(n)])
count = 0
while len(l) > 0:
    check = l[0] + k
    pas = 0
    for i in range(len(l)):
        if (l[i] <= check) and (pas < c):
            pas += 1
        else:
            break
    l = l[pas:]
    count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n, c, k = map(int, input().split())
l = sorted([int(input()) for i in range(n)])
count = 0
while len(l) > 0:
    check = l[0] + k
    pas = 0
    for i in range(len(l)):
        if (l[i] <= check) and (pas < c):
            pas += 1
    l = l[pas:]
    count += 1
print(count)

Submission status: Time Limit Exceeded

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

while done < n:
  for i in range(c,0,-1):
    t_sub = t[done:done+i]
    if t_sub[0] + k >= t_sub[-1]:
      done += i
      bus += 1
      break
      
print(bus)

Submission status: Time Limit Exceeded

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

T.sort()
counter = 0
while len(T) > 0:
  if len(T) == 1:
    T.pop()
    counter += 1
  else:
    c = 1
    while c <= len(T)-1:
      if T[c] - T[0] <= K:
        c += 1
      else:
        break
  
    del T[:min(c,C)]
    counter += 1

print(counter)

Submission status: Time Limit Exceeded

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

bus = []
ans = 0

while len(t) != 0:
	temp = t.pop(0)
	if len(bus) == 0:
		bus.append(temp)
	else:
		if temp < bus[0] + k:
			bus.append(temp)
			if len(bus) == c:
				ans += 1
				bus = []
		else:
			ans += 1
			bus = []

print(ans+1)

Submission status: Time Limit Exceeded

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

T.sort()
i = 0
ans = 0

while i < N:
    t = T[i]
    x = T.count(T[i]) 
    ans = ans + (x-1+C)//C 
    if T[N-1]<t+K:
        y = N-i
    else:
        for j in range(i+((x-1+C)//C-1)*C,N):
            if T[j]>t+K:
                y = j-i
                break
 
    y=min(C,y)
    i = i + y 

print(ans)

Submission status: Time Limit Exceeded

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

T.sort()
i = 0
ans = 0

while i < N:
    t = T[i]
    x = T.count(T[i])
    ans = ans + (x-1+C)//C
    for j in range(i+((x-1+C)//C-1)*C,N):
        if T[j]>t+K:
            y = j-i
            break
        y = N-i
            
    y=min(C,y)
    i = i + y 

print(ans)

Submission status: Time Limit Exceeded

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

T.sort()
i = 0
ans = 0

while i < N:
    t = T[i]
    x = T.count(T[i])
    ans = ans + (x-1+C)//C
    for j in range(i,N):
        if T[j]>t+K:
            y = j-i
            break
        y = N-i
            
    y=min(C,y)
    i = i + y 

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
n,c,k=map(int,input().split())
l=sorted([int(input()) for _ in range(n)],reverse=True)
ans=0
d=deque(l)
while len(d)!=0:
    ans+=1
    t=d.popleft()
    for i in range(c-1):
        if len(d)!=0 and d[0]>=t-k:
            d.popleft()
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

i = 0
bus = 0
while i < N:
    bus += 1
    lst = T[i:i+C]
    i += len(lst[lst - lst[0] <= K])
print(bus)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

i = 0
j = C
bus = 0
while i < N:
    bus += 1
    lst = T[i:j]
    i += len(lst[lst - lst[0] <= K])
    j = i + C
print(bus)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
N, C, K = map(int, input().split())
T = [int(input()) for i in range(N)]
T.sort()
T
answer = 0
while len(T) >0:
    limit = T[0] + K
    counter = 0
    while counter < C:
        if len(T) == 0:
            break
        t = T.pop(0)
        if t > limit:
            T = [t] + T
            break
        counter += 1
    answer += 1
print(answer)

Submission status: Time Limit Exceeded

Solution code:
n,c,k=map(int,input().split())
t=[int(input()) for _ in range(n)]
t.sort()
res=0
while(t):
    i=0
    j=t[0]+k
    if len(t)==1:
        res+=1
        break
    while(i<len(t) and t[i]<=j and i<c):
        i+=1
    res+=1
    t=t[i:]
print(res)

Submission status: Time Limit Exceeded

Solution code:
n,c,k=map(int,input().split())
t=[int(input()) for _ in range(n)]
t.sort()
res=0
while(t):
    i=0
    j=t[0]+k
    if len(t)==1:
        res+=1
        break
    while(i<len(t) and t[i]<=j and i<c):
        i+=1
    res+=1
    for _ in range(i):
        del t[0]
print(res)

Submission status: Time Limit Exceeded

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

T = sorted(T)
j = 0
ans = 0
while j < N:
    t = T[j]
    ret = bisect.bisect_right(T, t+K, lo=j, hi=N)
    if ret-j > C:
        ret = C
    j += ret-j
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

while flag == 0:
    if C < len(T) or T[-1]-T[0]>=K:
        if C < len(T):
            if T[0]+K<T[C-1]:
                T = [i for i in T if i > T[0]+K]
                ans += 1
            else:
                T = T[C:]
                ans += 1
        else:
            T = [i for i in T if i > T[0]+K]
            ans += 1
    else:
        flag = 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,C,K = map(int,input().split())
T = [int(input()) for i in range(N)]
T.sort()
def func(list1,num = 1):
    for i in range(1,len(list1)):
        wait = list1[i] - list1[0]
        if wait > K or i + 1 > C:
            return func(list1[i:],num + 1)
    return num
print(func(T))

Submission status: Time Limit Exceeded

Solution code:
N,C,K = map(int,input().split())
T = [int(input()) for i in range(N)]
T.sort()
def func(list1,num = 1):
    for i in range(len(list1)):
        wait = list1[i] - list1[0]
        if wait > K or i + 1 > C:
            return func(list1[i:],num + 1)
    return num
print(func(T))

Submission status: Time Limit Exceeded

Solution code:
n,c,k = map(int, input().split())
t = [int(input()) for i in range(n)]
t.sort()
ans = 1
while len(t) > 1:
    d = t[0]
    m = min(len(t),c)-1
    if t[m]-k <= d:
        t = t[m+1:]
    else:
        i = 0
        while 1:
            i += 1
            if t[i]-k > d:
                break
        t = t[i:]
    if len(t):
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

n,c,k = map(int, input().split())
t = [int(input()) for i in range(n)]
t.sort()
ans = 1
while len(t) > 1:
    d = t[0]
    m = min(len(t),c)-1
    if t[m]-k <= d:
        t = t[m+1:]
    else:
        i = bisect.bisect_left(t, d+k)
        t = t[i:]
    if len(t):
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,c,k = map(int, input().split())
t = [int(input()) for i in range(n)]
t.sort()
ans = 1
while len(t) > 1:
    d = t[0]
    i = 0
    while i < min(len(t),c):
        i += 1
        if i < len(t):
            if t[i]-k > d:
                break
    t = t[i:]
    if len(t):
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,c,k = map(int, input().split())
t = [int(input()) for i in range(n)]
t.sort()
ans = 0
while t:
    d = t[0]
    for i in range(min(c,len(t))):
        if d+k >= t[0]:
            t.pop(0)
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

t_list.sort()

count = 0
i = 0
while t_list:
    passenger = 1
    t = t_list.pop(0)
    count += 1
    while t_list:
        tmp = t_list.pop(0)

        if passenger < C and tmp - t <= K:
            passenger += 1
        else:
            t_list.insert(0, tmp)
            break

print(count)

Submission status: Time Limit Exceeded

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):
        cnt += 1
        
        if cnt == len(tk):
            break
        
        
    # バスの定員もしくはいる人数を乗せていく
    for _ in range(min(cnt,c)):
        tk.popleft()
    
    ans += 1
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,c,k=map(int,input().split())
t=[]
for i in range(n):
    t.append(int(input()))
t=list(reversed(sorted(t)))
ans=0
while t != []:
    t0 = t[-1]
    cnt=0
    while cnt<c and t != [] and t[-1] <= t0+k:
        t=t[:-1]
        cnt+=1
    ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,c,k=map(int,input().split())
t=[]
for i in range(n):
    t.append(int(input()))
t=list(reversed(sorted(t)))
ans=0
while t != []:
    t0 = t[-1]
    cnt=0
    while cnt<c and t != [] and t[-1] <= t0+k:
        t=t[:-1]
        cnt+=1
    ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
class Tree:
    def __init__(self, x):
        self.data = x
        self.right = None
        self.left = None
    
    def insert(self, value, valueList):
        if(value < self.data):
            if(self.left == None):
                self.left = Tree(value)
                valueList.insert(valueList.index(self.data), value)
            else:
                self.left.insert(value, valueList)
        else:
            if(self.right == None):
                self.right = Tree(value)
                valueList.insert(valueList.index(self.data)+1, value)
            else:
                self.right.insert(value, valueList)
        return valueList


def count_bus(N, C, K, tList):
    B = 0
    while(len(tList) > 0):
        firstTime = tList[0]
        leaveTime = tList[0] + int(K)
        count = 0
        for i in range(int(C)):
            if(i >= len(tList)):
                break
            if(tList[i] < leaveTime):
                count = count + 1
        tList = tList[count:]
        B = B + 1
    return B     

try:
    N, C, K = map(int, raw_input().strip().upper().split())
    tree = Tree(int(raw_input().strip()))
    valueList = [tree.data]
    for i in range(N-1):
        tree.insert(int(raw_input().strip()), valueList)
    print count_bus(N, C, K, valueList)
except EOFError:
    pass

Submission status: Time Limit Exceeded

Solution code:
class Tree:
    def __init__(self, x):
        self.data = x
        self.right = None
        self.left = None
    
    def insert(self, value):
        if(value < self.data):
            if(self.left == None):
                self.left = Tree(value)
            else:
                self.left.insert(value)
        else:
            if(self.right == None):
                self.right = Tree(value)
            else:
                self.right.insert(value)
        return 0
    
    def reconstruct_list(self):
        left = []
        right = []
        if(self.left != None):
            left = self.left.reconstruct_list()
        if(self.right != None):
            right = self.right.reconstruct_list()
        return left + [self.data] + right

def count_bus(N, C, K, tList):
    B = 0
    while(len(tList) > 0):
        firstTime = tList[0]
        leaveTime = tList[0] + int(K)
        count = 0
        for i in range(int(C)):
            if(i >= len(tList)):
                break
            if(tList[i] < leaveTime):
                count = count + 1
        tList = tList[count:]
        B = B + 1
    return B     

try:
    N, C, K = map(int, raw_input().strip().upper().split())
    tree = Tree(int(raw_input().strip()))
    for i in range(N-1):
        tree.insert(int(raw_input().strip()))
    tList = tree.reconstruct_list()
    print count_bus(N, C, K, tList)
except EOFError:
    pass

Submission status: Time Limit Exceeded

Solution code:
def count_bus(N, C, K, tList):
    B = 0
    while(len(tList) > 0):
        firstTime = tList[0]
        leaveTime = tList[0] + int(K)
        count = 0
        for i in range(int(C)):
            if(i >= len(tList)):
                break
            if(tList[i] < leaveTime):
                count = count + 1
        tList = tList[count:]
        B = B + 1
    return B

try:
    N, C, K = raw_input().strip().upper().split()
    tList = []
    for i in range(int(N)):
        tList.append(int(raw_input().strip()))
    
    tList.sort()
    print count_bus(N, C, K, tList)
except EOFError:
    pass

Submission status: Time Limit Exceeded

Solution code:
n,c,k = map(int,input().split())
#cは乗客kは時間
T = []
for i in range(n):
    t = int(input())
    T.append(t)
T.sort()
bus = 0
while(True):
    if len(T) == 0:
        break
    start = T[0]
    for i in range(c):
        if len(T)!=0: 
            if start+k >= T[0]:
                T.remove(T[0])
    bus += 1
print(bus)

Submission status: Accepted

Solution code:
N, C, K = map(int, input().split())
P = [int(input()) for _ in range(N)]
P.sort()
ans = 1
p_cnt = 0
last_b = P[0]
for p in P:
  if p <= last_b+K and p_cnt < C:
    p_cnt += 1
  else:
    last_b = p
    p_cnt = 1
    ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, math
from bisect import bisect_right
sys.setrecursionlimit(10**9)

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def main():
    N, C, K = mi()
    T = [ii() for i in range(N)]
    T.sort()

    cnt = 0
    i = 0

    while i < N:
        t = T[i]+K
        b = bisect_right(T, t)
        i = min(i+C, b)
        cnt += 1

    print(cnt)



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n, c, k, *t = map(int, open(0).read().split())
t.sort()
tmp = 0
cnt = 0
limit = t[0] + k
for time in t:
    if tmp == c or time > limit:
        limit = time + k
        tmp = 1
        cnt += 1
    else:
        tmp += 1
if tmp != 0:
    print(cnt + 1)
else:
    print(cnt)