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: Wrong Answer

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

t = sorted(t)

p = 0 # バスに乗っている人数
f = 0 # 最初にバスに乗った人の時間
b = 0 # バスの台数

for i in t:
    p += 1
    if f == 0:
        f = i
    if f + k == i or p >= c:
        # 現在の人を含める場合
        b += 1
        f = 0
        p = 0
    elif f + k < i:
        # 現在の人を含めない場合
        b += 1
        f = i
        p = 0

if 0 < f:
    b += 1

print(b)

Submission status: Wrong Answer

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

T.sort()

countBus = 0
startTime = 0
countPeople = 0
for i in range(N):
    countPeople += 1
    if startTime == 0:
        countBus = 1
        startTime = T[0]
    else:
        if (K <= T[i] - startTime) or (C < countPeople):
            countBus += 1
            countPeople = 1
            startTime = T[i]

print countBus

Submission status: Wrong Answer

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

T.sort()

countBus = 0
startTime = T[0]
countPeople = 0
for i in range(N - 1):
    countPeople += 1
    if (K <= (T[i + 1] - startTime)) or (C < countPeople):
        countBus += 1
        countPeople = 1
        startTime = T[i + 1]
    if i == N - 2:
        countBus += 1
print countBus

Submission status: Wrong Answer

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

countBus = 0
startTime = T[0]
countPeople = 0
for i in range(N - 1):
    countPeople += 1
    if (K <= (T[i + 1] - startTime)) or (C < countPeople):
        countBus += 1
        countPeople = 0
        startTime = T[i + 1]
    if i == N - 2:
        countBus += 1
print countBus

Submission status: Wrong Answer

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

T.sort()
print(T)

countBus = 0
startTime = T[0]
countPeople = 0
for i in range(N - 1):
    countPeople += 1
    if (K <= (T[i + 1] - startTime)) or (C < countPeople):
        countBus += 1
        countPeople = 0
        startTime = T[i + 1]
    if i == N - 2:
        countBus += 1
print countBus

Submission status: Wrong Answer

Solution code:
n, c, k = map(int, input().split(" "))
t = []

for i in range(0, n):
    t.append(int(input()))

t = sorted(t)

p = 0 # バスに乗っている人数
f = 0 # 最初にバスに乗った人の時間
b = 0 # バスの台数

for i in t:
    p += 1
    if f == 0:
        f = i
    if f + k <= i or p > c:
        b += 1
        f = i
        p = 0

if 0 < f:
    b += 1

print(b)

Submission status: Wrong Answer

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

T.sort()
bus = 1
s = T[0]
c = 1
for t in T[0:]:
	if t > s+K or c == C:
		print s, t
		c = 0
		s = t
		bus += 1
	c += 1
print bus

Submission status: Wrong Answer

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

N,C,K=map(int,raw_input().strip().split(" "))

T=[]
bmember=0
bf=0
b_cnt=0

for i in range(N):
    T.append(int(raw_input()))

T.sort()
for i in range(N):
    if bmember==0:
        bf=T[i]
        bmember+=1
    else:
        if T[i]-bf<K:
            bmember+=1
            if bmember==3:
                bmember=0
                b_cnt+=1
        else:
            bmember=1
            bf=T[i]
            b_cnt+=1

if bmember>0:
    b_cnt+=1

print  b_cnt

Submission status: Wrong Answer

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

countBus = 0
startTime = T[0]
countPeople = 0
for i in range(N-1):
    countPeople += 1
    if (K < (T[i+1] - startTime)) or (C < countPeople):
        countBus += 1
        countPeople = 0
        startTime = T[i+1]
    if i == N-2:
        countBus += 1
print countBus

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
# sys.setrecursionlimit(10000)


def main():
    # xs = ['5 3 5', '1', '2', '3', '6', '12']
    # input = get_input(xs)

    # 入力処理
    N, C, K = [int(x) for x in input().split()]
    Ts = [int(input()) for i in range(N)]

    print("N={}, C={}, K={}".format(N, C, K),
          file=sys.stderr)

    # アルゴリズム本体
    M = 1               # バスの数
    n = 0               # 現在のバスに乗っている人数
    Tlim = Ts[0] + K    # 現在のバスの発車ギリギリの時刻

    for T in Ts:
        if T > Tlim or n >= C:
            # 次のバスを準備
            M += 1
            Tlim = T + K
            # 次のバスに一人追加
            n = 1
        else:
            # このバスに一人追加
            n += 1

    # 出力
    print(M)

# def get_input(xs):
#     xs_iter = iter(xs)
#     def fake_input():
#         return next(xs_iter)
#
#     return fake_input


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
N,C,K=map(int,input().split())
people = np.zeros(N)

for i in range(N):
    people[i]=int(input())
    
people=np.sort(people)

count=0
ride=C+1
ridetime=0
for i in range(N):
    if ridetime+K>people[i] and ride<C:
        ride+=1
    else:
        count+=1
        ride=1
        ridetime=people[i]

print(count)

Submission status: Wrong Answer

Solution code:
N, C, K = map(int, input().split())
T = []
bus_count = 1
index = 0
for i in range(N):
    T.append(int(input()))
T.sort()
deperture_time = T[0] + K
for i, j in enumerate(T, 1):
    if j > deperture_time:
        bus_count += 1
        index = i
        deperture_time = j + K
        continue
    if i - index == C:
        bus_count += 1
        index = i + 1
        deperture_time = j + K
        continue
print(bus_count)

Submission status: Wrong Answer

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

countBus = 1
startTime = T[0]
countPeople = 0
for i in range(N-1):
    countPeople += 1
    if (K < (T[i+1] - startTime)) or (C < countPeople):
        countBus += 1
        countPeople = 0
        startTime = T[i+1]
    elif i == N-2:
        countBus += 1
print countBus

Submission status: Wrong Answer

Solution code:
n, c, k = map(int, input().split(" "))
t = []

for i in range(0, n):
    t.append(int(input()))

t = sorted(t)

p = 0 # バスに乗っている人数
f = 0 # 最初にバスに乗った人の時間
b = 0 # バスの台数

for i in t:
    p += 1
    if f == 0:
        f = i
    if f + k < i or p > c:
        b += 1
        f = i
        p = 0

if 0 < f:
    b += 1

print(b)

Submission status: Wrong Answer

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

countBus = 1
startTime = T[0]
countPeople = 0
for i in range(N-1):
    countPeople += 1
    if (K < (T[i+1] - startTime)) or (C < countPeople):
        countBus += 1
        countPeople = 0
        startTime = T[i+1]
print countBus

Submission status: Wrong Answer

Solution code:
n, c, k = map(int, input().split(" "))
t = []

for i in range(0, n):
    t.append(int(input()))

t = sorted(t)

p = 0 # バスに乗っている人数
f = 0 # 最初にバスに乗った人の時間
b = 0 # バスの台数

for i in t:
    p += 1
    if f == 0:
        f = i
    if f + k < i or p >= c:
        b += 1
        f = i
        p = 0

if 0 < f:
    b += 1

print(b)

Submission status: Wrong Answer

Solution code:
import numpy as np
N,C,K=map(int,input().split())
people = np.zeros(N)

for i in range(N):
    people[i]=int(input())
    
people=np.sort(people)

count=0
ride=C+1
ridetime=0
for i in range(N):
    if ridetime+K>people[i] and ride<=C:
        ride+=1
    else:
        count+=1
        ride=1
        ridetime=people[i]

print(count)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# greedy algorithm
inp = list(map(int, input().split()))
N = inp[0]
C = inp[1]
K = inp[2]

t = []
for i in range(0, N):
    t.append(int(input()))

t.sort()

b = 0
p = 0
s = -1
for i in range(0, N):
    # first passenger
    if s == -1:
        s = t[i]
        p = 1
        continue
    # passenger gets anger if he takes the last bus
    if t[i] > s + K:
        b += 1
        p = 1
        s = t[i]
        continue
    # following passenger in time
    else:
        p += 1
    # passenger limit or last passenger
    if p == C or i == N - 1:
        b += 1
        p = 0
        s = -1
# last passenger left
if p > 0:
    b += 1
print(b)

Submission status: Wrong Answer

Solution code:
N, C, K = map(int, input().rstrip().split())
TT = sorted(map(int, [input() for _ in range(N)]))
startT = TT[0]
bus_count = 1
p = 1
for T in TT[1:]:
    if T - startT > K or p > C:
        bus_count += 1
        startT = T
        p = 1
    else:
        p += 1
print(bus_count)

Submission status: Wrong Answer

Solution code:
import sys

INF = 10**9+7

stdin = sys.stdin
def na(): return map(int, stdin.readline().split())
def nal(): return list(map(int, stdin.readline().split()))
def ns(): return stdin.readline().strip()
def nsl(): return list(stdin.readline().strip())
def ni(): return int(stdin.readline())


n, c, k = nal()

t = []
for i in range(n):
    t.append(ni())
t.sort()

ans = 0
cnt = 0
tmp = t[0] + k
for i in range(1, n):
    cnt += 1
    en = 0
    if(tmp < t[i] or cnt == c):
        ans += 1
        cnt = 0
        tmp = t[i] + k
        en = 1

print(ans + en)

Submission status: Wrong Answer

Solution code:
N, C, K = map(int, input().rstrip().split())
TT = sorted(map(int, [input() for _ in range(N)]))
bus = [0] * C
startT = TT[0]
bus_count = 1
for T in TT[1:]:
    if T - startT > C:
        bus_count += 1
        startT = T
print(bus_count)

Submission status: Wrong Answer

Solution code:
N, C, K = map(int, input().split())
T = []
bus_count = 1
index = 0
for i in range(N):
    T.append(int(input()))
deperture_time = T[0] + K
for i, j in enumerate(T, 1):
    if j > deperture_time:
        bus_count += 1
        index = i
        deperture_time = j + K
        continue
    if i - index == C:
        bus_count += 1
        index = i + 1
        deperture_time = j + K
        continue
print(bus_count)

Submission status: Wrong Answer

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

ni,nt,ans = 0,0,0
while 1:
    if ni >= n:
        break
    nt = t[ni]
    for i in range(1,c+1):
        if ni+i<n and t[ni+i] < nt + k:
            ni += 1
        else:
            break
    ni += 1
    ans += 1
print(ans)

Submission status: Wrong Answer

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

bus_num = 0
while T:
    passengers = 0
    t = T[0]
    T.pop(0)
    while T and passengers < C and t + K > T[0]:
        T.pop(0)
        passengers += 1
    bus_num +=1
print(bus_num)

Submission status: Wrong Answer

Solution code:
def main():
    N,C,K = map(int, input().split())
    times = [int(input()) for n in range(N)]
    times.sort()

    first = 0
    index = 1
    count = 1

    while index <= N-1:
        if times[index] - times[first] <= C:
            index += 1
        else:
            count += 1
            first = index
            index += 1

    print(count)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N, C, K = map(int, raw_input().split())
nBus = 0
curBus = []
for i in xrange(N):
    t = int(raw_input())
    if len(curBus) == 0:
        curBus.append(t)
        continue
    if (t - curBus[0] > K) or len(curBus) == C:
        nBus += 1
        curBus = [t]
    else:
        curBus.append(t)
if len(curBus) > 0:
    nBus += 1
print nBus

Submission status: Wrong Answer

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

cnt = 1
k = 0
t0 = T[0]
c = 0
for t in T:
    if c < C and t <= t0 + K:
        c += 1
    else:
        c = 0
        t0 = t
        cnt += 1
print cnt

Submission status: Wrong Answer

Solution code:
temp=input().split()
N=int(temp[0])
C=int(temp[1])
K=int(temp[2])
T=[int(input()) for i in range(N)]

T.sort()
ans=1
first=T[0]
bus=1
for i in range(1,N):
	if T[i]<=first+K:
		if bus<C:
			bus+=1
			continue
		else:
			ans+=1
			first=T[i]
			bus=1
	else:
		ans+=1
		first=T[i]
print(ans)

Submission status: Wrong Answer

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

import sys, math, random, operator
from string import ascii_lowercase, ascii_uppercase
from fractions import Fraction, gcd
#from decimal import Decimal, getcontext
from itertools import product, permutations, combinations
from Queue import Queue, PriorityQueue
from collections import deque, defaultdict, Counter
#getcontext().prec = 100

MOD = 10**9 + 7
INF = float("+inf")

if sys.subversion[0] == "PyPy":
    import io, atexit
    sys.stdout = io.BytesIO()
    atexit.register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))
    sys.stdin = io.BytesIO(sys.stdin.read())
    raw_input = lambda: sys.stdin.readline().rstrip()
pr = lambda *args: sys.stdout.write(" ".join(str(x) for x in args) + "\n")
epr = lambda *args: sys.stderr.write(" ".join(str(x) for x in args) + "\n")
die = lambda *args: pr(*args) ^ exit(0)

read_str = raw_input
read_strs = lambda: raw_input().split()
read_int = lambda: int(raw_input())
read_ints = lambda: map(int, raw_input().split())
read_float = lambda: float(raw_input())
read_floats = lambda: map(float, raw_input().split())

"---------------------------------------------------------------"

N, C, K = read_ints()
arr = []
for i in xrange(N):
    t = read_int()
    arr.append(t)
arr.sort()
# epr(arr)
last_bus = INF
nfree = 0
ans = 0
for t in reversed(arr):
    if t >= last_bus - K and nfree > 0:
        nfree -= 1
    else:
        print "TAKE FOR", t-K, t
        ans += 1
        nfree = C - 1
        last_bus = t

print ans

Submission status: Wrong Answer

Solution code:
from operator import sub
n, c, k = map(int, input().split())
t = sorted([int(input()) for i in range(n)])
d = list(map(sub, t[1:], t))
count = 1
cur = 1
for v in d:
  if v > k:
    count += 1
    cur = 1
  else:
    cur += 1
    if cur > c:
      count += 1
      cur = 1
print(count)

Submission status: Wrong Answer

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

bus = 0
bus_t = None
bus_on_board = 0

for t in Ts:
	if bus_t is not None and t < bus_t and bus_on_board < C:
		bus_on_board += 1
	else:
		bus += 1
		bus_t = t + K
		bus_on_board = 1
print(bus)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys

def s():
    return raw_input().strip()
def n():
    return int(raw_input())
def d():
    return float(raw_input())

def ls():
    return raw_input().strip().split()
def ln():
    return map(int, raw_input().strip().split())
def ld():
    return map(float, raw_input().strip().split())

def fs():
    return [raw_input().strip() for i in xrange(input())]
def fn():
    return [int(raw_input().strip()) for i in xrange(input())]
def fd():
    return [float(raw_input().strip()) for i in xrange(input())]

N, C, K = ln()

T = []
for i in xrange(N):
    T.append(n())

T.sort()

bus = 0
last = T[0]
count = 1
for t in T[1:]:
    if t - last >= K or count == C:
        bus += 1
        last = t
        count = 1
    else:
        count += 1
bus += 1

print bus

Submission status: Time Limit Exceeded

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

ans = 0
while T != []:
    cnt = 0
    for i in range(len(T)):
        cnt += 1
        if T[i] - T[0] > K or cnt > C:
            T = T[i:]
            ans += 1
            break
        if i == len(T)-1:
            ans += 1
            T = []
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

N, C, K = map(int, input().split())
t_dic = {}
for j in range(N):
    t_num = int(input())
    num = t_dic.get(t_num, 0)
    t_dic[t_num] = num + 1

t_list = sorted(t_dic.keys())
removed_man_dic = {}
total_car = 0
for i, t in enumerate(t_list):
    limit = t + K
    limit_num = t_dic[t] - removed_man_dic.get(t, 0)
    if limit_num == 0:
        continue
    car_num = int(math.ceil(limit_num / C))
    total_car += car_num
    passenger = C * car_num
    remaining_seat = passenger - limit_num
    removed_man_dic = {}
    for j in t_list[i+1:]:
        if j >= limit:
            break
        num = t_dic.get(j, 0)
        if num <= remaining_seat:
            remaining_seat -= num
            removed_man_dic[j] = num
        else:
            removed_man_dic[j] = remaining_seat
            break

print(total_car)

Submission status: Time Limit Exceeded

Solution code:
import math

N, C, K = map(int, input().split())
t_dic = {}
for i in range(N):
    t_num = int(input())
    num = t_dic.get(t_num, 0)
    t_dic[t_num] = num + 1

t_list = t_dic.keys()
removed_man_dic = {}
total_car = 0
for key, value in sorted(t_dic.items(), key=lambda x: x[0]):
    limit = key + K
    limit_num = t_dic[key] - removed_man_dic.get(key, 0)
    if limit_num == 0:
        continue
    car_num = int(math.ceil(limit_num / C))
    total_car += car_num
    passenger = C * car_num
    remaining_seat = passenger - limit_num
    removed_man_dic = {}
    for i in range(key + 1, limit + 1):
        if i not in t_list:
            continue
        num = t_dic.get(i, 0)
        if num <= remaining_seat:
            remaining_seat -= num
            removed_man_dic[i] = num
        else:
            removed_man_dic[i] = remaining_seat
            break

print(total_car)

Submission status: Time Limit Exceeded

Solution code:
import math

N, C, K = map(int, input().split())
t_dic = {}
for i in range(N):
    t_num = int(input())
    num = t_dic.get(t_num, 0)
    t_dic[t_num] = num + 1

removed_man_dic = {}
total_car = 0
for key, value in sorted(t_dic.items(), key=lambda x:x[0]):
    limit = key + K
    limit_num = t_dic[key] - removed_man_dic.get(key, 0)
    if limit_num == 0:
        continue
    car_num = int(math.ceil(limit_num / C))
    total_car += car_num
    passenger = C * car_num
    remaining_seat = passenger - limit_num
    removed_man_dic = {}
    for i in range(key + 1, limit + 1):
        num = t_dic.get(i, 0)
        if num <= remaining_seat:
            remaining_seat -= num
            removed_man_dic[i] = num
        else:
            removed_man_dic[i] = remaining_seat
            break

print(total_car)

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import deque, defaultdict
def main():
    n, c, k = map(int, input().split())
    times = defaultdict(int)
    for _ in range(n):
        times[int(input()) + k] += 1

    r = 0
    for i1 in range(min(times.keys()), max(times.keys()) + 1):
        if times[i1]:
            if times[i1] >= c:
                p = times[i1] // c
                r += p
                times[i1] - p * c
            else:
                r += 1
                g = c - times[i1]
                for i2 in range(i1+1, i1+k+1):
                    if times[i2]:
                        if times[i2] <= g:
                            g -= times[i2]
                            times[i2] = 0
                        else:
                            times[i2] -= g
                            break
    print(r)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import deque, defaultdict
def main():
    n, c, k = map(int, input().split())
    times = [int(input()) + k for _ in range(n)]
    times.sort()
    times = deque(times)

    r = 0
    for i1 in range(max(times) + 1):
        if times and i1 == times[0]:
            r += 1
            g = 0
            while g < c:
                if times and times[0] <= i1 + k:
                    times.popleft()
                    g += 1
                else:
                    break
    print(r)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
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 = 0
    for i in range(min(c, n - ind)):
        if la[ind + i] <= lak[ind]:
            ride += 1
    ind += ride
    ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
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 = 0
    for i in range(min(c, n - ind)):
        if la[ind + i] <= lak[ind]:
            ride += 1
    ind += ride
    ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
kyaku, teiin, jikan = map(int, input().split(" "))
a=sorted([(int)(input()) for i in range(kyaku)])
count = 0
while(True):
  #print(a)
  if len(a) > teiin:
    if a[0] + jikan >= a[teiin]:
      a = a[teiin:]
    else:
      a = a[bisect.bisect_left(a, a[0] + jikan):]
  else:
    if a[0] + jikan >= a[-1]:
      count += 1
      break
    else:
      a = a[bisect.bisect_left(a, a[0] + jikan):]
  count += 1
print(count)

Submission status: Time Limit Exceeded

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()
    ret = 0
#    print(Ti)
    while len(Ti)>0:
        Tto = K + Ti[0]
        Ti = Ti[min(C,bisect_right(Ti[:min(C,len(Ti))], Tto)):]
        ret += 1
#        print(Ti)
    print(ret)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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()
    ret = 0
#    print(Ti)
    while len(Ti)>0:
        Tto = K + Ti[0]
        Ti = Ti[min(C,bisect_right(Ti, Tto)):]
        ret += 1
#        print(Ti)
    print(ret)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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()
    ret = 0
#    print(Ti)
    while len(Ti)>0:
        Tto = K + Ti[0]
        Ti = Ti[min(C,bisect_right(Ti, Tto)):]
        ret += 1
#        print(Ti)
    print(ret)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n,c,m = map(int,input().split(" "))
ar = [int(input()) for i in range(n)]
ar.sort()
count = 0
s = 0
g = c
while True:
    if max(ar[s:g]) - min(ar[s:g]) < m:
        count += 1
        s = g
        g = min(s + c,n)
    else:
        g -= 1
    if s == n:
        break
print(count)

Submission status: Time Limit Exceeded

Solution code:
n,c,k=map(int,input().split())
a=sorted([int(input()) for _ in range(n)],reverse=True)
cnt=0
while len(a) > 0:
    b=a.pop()
    cnt+=1
    if len(a)==0:
        break
    for i in range(c-1):
        if a[-1]<=b+k:
            a.pop()
            if len(a)==0:
                break
        
print(cnt)

Submission status: Time Limit Exceeded

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

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

buss = []
x, *T = T
bus = [x]
while T:
    while T:
        t, *T = T
        if t <= x + K and len(bus) < C:
            bus.append(t)
        else:
            x = t
            buss.append(bus)
            bus = [x]
            break
buss.append(bus)
print(len(buss))

Submission status: Time Limit Exceeded

Solution code:
# AGC011 A Airport Bus
import bisect

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

t_list.sort()
ans = 0

while len(t_list) > 0:
    _tmp = t_list[0] + k
    _idx = bisect.bisect_right(t_list, _tmp)
    if c <= _idx + 1:
        t_list = t_list[c:]
    else:
        t_list = t_list[_idx:]
    ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

ans = 0
while len(t)>0:
	mens = bisect.bisect_right(t,t[0]+k)
	bus = mens//c
	if bus!=0:
		ans+=bus
		t = t[bus*c:]
	else:
		ans+=1
		t = t[mens:]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

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

Submission status: Time Limit Exceeded

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

ans = 0
while len(t)>0:
	pi = t[0]
	mens = 1
	for i in range(1,len(t)):
		if pi+k>=t[i]:
			mens+=1
		else:
			break
	bus = mens//c
	if bus!=0:
		ans+=bus
		t = t[bus*c:]
	else:
		ans+=1
		t = t[mens:]
print(ans)

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 = 1
	for i in range(1,len(t)):
		if pi+k>=t[i]:
			mens+=1
		else:
			break
	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:
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))


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:

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

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)