Problem:


Score : 300 points

Problem Statement

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

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

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

Constraints

2 \leq N \leq 100000

1 \leq C \leq 10^9

1 \leq K \leq 10^9

1 \leq T_i \leq 10^9

C, K and T_i are integers.

Input

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

N C K
T_1
T_2
:
T_N

Output

Print the minimum required number of buses.

Sample Input 1

5 3 5
1
2
3
6
12

Sample Output 1

3

For example, the following three buses are enough:

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

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

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

Sample Input 2

6 3 3
7
6
2
8
10
6

Sample Output 2

3



Sample input:
5 3 5
1
2
3
6
12


Sample output:
3

Submission status: Accepted

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

for i in range(N):
    t_list[i] = int(input())

t_list.sort()

bus_cnt = 0
bus_member = []
for t in t_list:
    if len(bus_member) != 0 and K < t - bus_member[0]:
        bus_member.clear()
        bus_cnt += 1

    bus_member.append(t)

    if C <= len(bus_member):
        bus_member.clear()
        bus_cnt += 1

if len(bus_member) != 0:
    bus_cnt += 1

print(bus_cnt)

Submission status: Accepted

Solution code:
class Queue:
    class Node:
        def __init__(self, key):
            ## self.key, self.next
            self.key = key
            self.next = None

    def __init__(self, N):
        self.head = None
        self.tail = None
        self.size = 0
        self.N = N

    def push(self, x):
        if self.size >= self.N:
            print 'error: size is N'
            return None
        self.size += 1
        node = self.Node(x)
        if self.size == 1:
            self.head = node
            self.tail = self.head
            #print 'add (zero banme-no queue):', self.head.key
        else:
            self.tail.next = node
            self.tail = node
            #print 'add:', self.tail.key

    def pop(self):
        if self.size < 1:
            print 'error: size is 0'
            return None
        self.size -= 1
        x = self.head.key
        self.head = self.head.next
        #print 'pop', x
        return x

    def get_size(self):
        return self.size

    def PrintAll(self):
        c_node = self.head
        while c_node is not None:
            print c_node.key,
            c_node = c_node.next
        print
    def get_head(self):
        return self.head.key

N, C, K = map(lambda x:int(x), raw_input().split())

T_raw=[]
for i in range(N):
    T_raw.append(int(raw_input()))

T_raw.sort()
T = Queue(N)
for i in range(N):
    T.push(T_raw[i])

result=0
while 1:
    #T.PrintAll()
    Bus=[]
    while 1:
        Bus.append(T.pop())
        if T.get_size() == 0 or Bus[0]+K < T.get_head() or len(Bus) == C:
            result+=1
            break
        
    if T.get_size() == 0:
        break
        
print result

Submission status: Accepted

Solution code:


def main():
	n = 0 #乗客数
	c = 0 #バスの定員
	k = 0 #猶予
	arraival_time = [] 

	n,c,k = input().split(' ')
	n = int(n)
	c = int(c)
	k = int(k)

	for i in range(n):
		tmp = int(input())
		arraival_time.append(tmp)

	arraival_time.sort()
	counting_bus = 0

	while(1):
		passenger = []
		times = 0
		rslt = making_bus(c, k, arraival_time, passenger, times) 
		if rslt == 0:
			break
		elif rslt == 1:
			counting_bus += 1

	print(counting_bus)
		
		

def making_bus(c, k, arraival_time, passenger,times):
	if arraival_time:
		if not passenger:
			passenger.append(arraival_time.pop(0))
			times += 1
			#recursion
			making_bus(c, k, arraival_time, passenger, times)
			return 1
	
		elif (len(passenger) < c):
			if (arraival_time[0]-passenger[0] <= k):
				passenger.append(arraival_time.pop(0))
				times += 1
				#recursion
				making_bus(c, k, arraival_time, passenger, times)
				return 1
			else:
				return 1
		else:
			return 1
				
	elif times == 0:
		return 0
	elif times > 0:
		return 1







if __name__ == '__main__':
	main()

Submission status: Accepted

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

first = -1
cnt = 0
ans = 1
for t in T:
    if first == -1:
        first = t
        cnt = 1
    else:
        if first + k < t or c == cnt:
            first = t
            cnt = 1
            ans += 1
        else:
            cnt += 1
print ans

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()


def main():
    n,c,k = LI()
    a = [II() for _ in range(n)]
    a.sort()
    m = a[0]
    t = 1
    r = 0
    for ai in a[1:]:
        if ai > m+k or t == c:
            r += 1
            t = 1
            m = ai
            continue
        t += 1

    if t > 0:
        r += 1
    return r

print(main())

Submission status: Accepted

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

def identity(x):
    return x

def mapv(f,s):
    return list(map(f,s))

def readln():
    _res = mapv(int,str(input()).split(' '))
    return _res

def seq(n,f=(lambda x: 0)):
    return [f(i) for i in range(0,n)]

n,c,k = readln()
t = [0 for i in range(0,n)]
for i in range(0,n):
    t[i] = int(input())
t = sorted(t)
ans,left = 0,0
while left < n:
    right = left
    while right < n and right - left < c and t[right] - t[left] <= k :
        right = right + 1
    ans = ans + 1
    left = right
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import os
import numpy as np

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


v = list()

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

v.sort()

M = 1000000009
now_n = 0
now_f = M
ans = 0

for i in range(0,N):
  if now_n >= C or (now_f != M and v[i]-now_f > K):
    ans += 1
    now_n = 0
    now_f = M
  now_f = min(now_f, v[i])
  now_n += 1

if now_n != 0:
  ans += 1

# print(v)
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

n_cus, n_bus, n_wai = map(int, input().split())
l_arr = [int(input()) for i in range(n_cus)]
l_arr.sort()

n_time_angry = 0
n_now_sheet = n_bus
l_waiting_cus = []
n_need_bus = 0

for arr in l_arr:
    if arr <= n_time_angry and n_now_sheet > 0:
        n_now_sheet -= 1
    else:
        n_time_angry = arr + n_wai
        n_now_sheet = n_bus - 1
        n_need_bus += 1
        
print(n_need_bus)

Submission status: Accepted

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

from sys import stdin

N,C,K=map(int,raw_input().split())
T=map(int,stdin.read().split())

T.sort()
t_star=T[0]
b_star=0
cnt=0
for b,t in enumerate(T):
    if t-t_star>K or b-b_star+1>C:
        cnt+=1
        t_star=t
        b_star=b

print cnt+1

Submission status: Accepted

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

bus = 0
new_bus = True
start_time = 0
capacity = 0

while t:
    time = t[0]
    if new_bus:
        new_bus = False
        capacity = 0
        start_time = time
        bus += 1

    wait_time = time - start_time
    if wait_time > k:
        if t:
            new_bus = True
            continue
        else:
            bus += 1
            break

    t.pop(0)
    capacity += 1

    if capacity == c:
        new_bus = True
        continue

print(bus)

Submission status: Accepted

Solution code:
# import sys
# sys.stdin = open('a2.in')

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

res = 0
room = c
bus_start = None

for t in arrivals:

    if room == c:
        bus_start = t

    has_left_because_angry_passenger = bus_start + k < t
    if has_left_because_angry_passenger:
        res += 1
        room = c
        bus_start = t

    room -= 1

    if room == 0:
        res += 1
        room = c

if room < c:
    res += 1

print(res)

Submission status: Accepted

Solution code:
from __future__ import division
import math
from collections import deque

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

T = [input() for i in xrange(N)]
T.sort()
#print T
minT = T[0]
minTidx = 0
lenT = len(T)
bus = 0

for i in xrange(lenT):
    v = T[i]

    diffH = v - minT
    diff = i - minTidx
    if diffH > K:
        bus += 1
        minTidx += min(C,diff)
        minT = T[minTidx]
#        print(i,"diffH>K",bus,minTidx,minT)

    diff = i - minTidx
    if i==lenT-1:
        cnt = math.ceil((diff+1) / C)
        bus += cnt
#        print(i,"last", cnt, bus)
    else:
        diff = i - minTidx
        if (diff+1) >= C:
            bus += 1
            minTidx += C
            minT = T[minTidx]
#            print(i,"(diff+1)>=C",bus,minTidx,minT)


print int(bus)

Submission status: Accepted

Solution code:
def main():
    N, C, K = map(int, input().split())
    i = 0
    T = []
    while i < N:
        T.append(int(input()))
        i += 1
    T.sort()
    T.reverse()

    c = 1
    i = 1
    bus = 1
    time = T[0]
    while i < N:
        if time - T[i] > K or c == C:
            bus += 1
            c = 1
            time = T[i]
        elif time - T[i] <= K:
            c += 1
        i += 1

    print(str(bus))

main()

Submission status: Accepted

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:
    if f == 0:
        f = i
    elif f + k < i or c <= p:
        b += 1
        f = i
        p = 0
    p += 1

b += 1

print(b)

Submission status: Accepted

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[1:]:
	if t > s+K or c == C:
		c = 0
		s = t
		bus += 1
	c += 1
print bus

Submission status: Accepted

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


def main():
    # 入力処理
    N, C, K = [int(x) for x in input().split()]
    Ts = sorted([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)


if __name__ == '__main__':
    main()

Submission status: Accepted

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: Accepted

Solution code:
import collections
n,c,k = map(int,input().split())
d = collections.deque()
ans = 0
lis = []
for _ in range(n):
    lis.append(int(input()))
lis.sort()

wait = lis[0]
for tm in lis[1:]:

    if tm > wait+k:
        ans += 1
        d.clear()
        wait = 1000000000
    d.append(tm)
    if len(d) == c-1:
        ans += 1
        d.clear()
        wait = 1000000000

    if len(d)!=0 and wait == 1000000000:
        wait = d.popleft()


if c==1: ans = n-1
print(ans+1)

Submission status: Accepted

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):
    # passenger limit or last passenger
    if p == C:
        b += 1
        p = 0
        s = -1
    # 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
# last passenger left
if p > 0:
    b += 1
print(b)

Submission status: Accepted

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
    if(tmp < t[i] or cnt == c):
        ans += 1
        cnt = 0
        tmp = t[i] + k

print(ans + 1)

Submission status: Accepted

Solution code:
n,c,k=map(int,raw_input().split())
t=[int(raw_input()) for _ in xrange(n)]
t.sort()
i=0
ans=0
#print t
while i<n:
    li=t[i]+k
    cnt=0
    f=0
    #print t[i]
    while i<n and t[i]<=li:
        cnt+=1
        if cnt==c:
            f=1
            ans+=1
            cnt=0
        i+=1
    if f==0:
        ans+=1
    else:
        i-=cnt
print ans

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,c,k = [int(x) for x in input().split()]
l = []
for x in range(n):
    num = int(input())
    second = num+k;
    l.append([num,second])

cnt = 1
pas = 1;
l = sorted(l,key=lambda x:x[1])
hold = l[0];
for x in range(1,n):
    if l[x][0] <= hold[1]:
        if pas == c:
            cnt += 1
            pas = 1
            hold = l[x]
        else:
            pas += 1
        pass
    else:
        cnt+= 1
        hold = l[x]
        pas = 1
print(cnt)

Submission status: Accepted

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

for _ in xrange(n):
    arrive.append(input())
arrive = sorted(arrive)

i = 0
buses = 0
while i < len(arrive):
    dep = arrive[i] + k
    j = 1
    while j < c and len(arrive) > j + i:
        if arrive[j + i] <= dep:
            j += 1
        else:
            break
    buses += 1

    i += j

print buses

Submission status: Accepted

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: Accepted

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])
            else:
                break
    bus += 1
print(bus)

Submission status: Accepted

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: Accepted

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

Submission status: Accepted

Solution code:
a = [int(x) for x in input().strip().split()]
t = []
for i in range(a[0]):
  t.append(int(input().strip()))
t.sort()

m = 0
i = 0
while True:
  if i+a[1] - 1 > a[0] - 1:
    ii = a[0] - 1
  else:
    ii = i+a[1] - 1
  if t[ii] - t[i] <= a[2]:
    i = ii + 1
    m += 1
  else:
    for j in range(i+1, ii+1):
      if t[j] - t[i] > a[2]:
        m += 1
        i = j
        break
  if i == a[0]:
    break

print(m)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import stdin
def main():
    n, c, k = map(int, stdin.readline().split())
    t = map(int, stdin.read().split())
    t.sort()
    p = t[0]
    ans = 0
    j = 0
    for i, x in enumerate(t):
        if x - p > k or i - j + 1 > c:
            ans += 1
            p = x
            j = i
    print ans + 1
main()

Submission status: Accepted

Solution code:
n, c, k = map(int, input().split())
t = sorted([int(input()) for i in range(n)])
count = 0
cur_t = -k
cur_c = 0
for v in t:
  if v - cur_t > k:
    count += 1
    cur_c = 1
    cur_t = v
  else:
    cur_c += 1
    if cur_c > c:
      count += 1
      cur_c = 1
      cur_t = v
print(count)

Submission status: Accepted

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

t.sort(reverse=True)
bus = 0
while t!=[]:
	init = t.pop()
	count = 1
	while t!=[]:
		if count >= C:
			break
		now = t[-1]
		if now - init > K:
			break
		t.pop()
		count += 1
	bus+=1

print(bus)

Submission status: Accepted

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
    rider_num = 1

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

    print(count)

if __name__ == "__main__":
    main()

Submission status: Accepted

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: Accepted

Solution code:
# coding: utf-8
def getLnInputs():
    return input().split()


def getLnIntInputs():
    return list(map(int, getLnInputs()))


def main():
    N, C, K = getLnIntInputs()

    a_queue = []
    bus_count = 0
    for _ in range(N):
        a_queue.append(int(input()))

    a_queue = sorted(a_queue)
    p_queue = []

    for i in range(N):
        t = a_queue[i]
        if len(p_queue) != 0 and t - p_queue[0] > K:
            p_queue = [t]
            bus_count += 1
            continue

        p_queue.append(t)

        if len(p_queue) == C:
            p_queue = []
            bus_count += 1

    if len(p_queue):
        bus_count += 1

    print(bus_count)
    return


main()

Submission status: Accepted

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

time_of_bus = 0
num_of_people = 0
num_of_bus = 0
for i in range(n):
    if time_of_bus == 0:
        time_of_bus = t[i] + k
        num_of_people = 1
        num_of_bus += 1
    elif t[i] <= time_of_bus and num_of_people < c:
        num_of_people += 1
    else:
        time_of_bus = t[i] + k
        num_of_people = 1
        num_of_bus += 1
print(num_of_bus)

Submission status: Accepted

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
		bus=1
		first=T[i]
print(ans)

Submission status: Accepted

Solution code:
N,C,K = map(int,input().split())
A = []
for n in range(N):
	a = int(input())
	A.append(a)
A.sort()
b = 0
for a in A:
	if b == 0:
		b = 1
		c = 1
		t = a
	elif c >= C:
		b = b + 1
		c = 1
		t = a
	elif a <= t + K and c < C:
		c = c + 1
	elif a > t + K:
		b = b + 1
		c = 1
		t = a
print(b)

Submission status: Accepted

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

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

Submission status: Accepted

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

a = 0

c = 0
l = t[0]
for i in range(N):
    if c == C or t[i] - l > K:
        a += 1
        c = 0
        l = t[i]
    
    c += 1

if c > 0:
    a += 1

print(a)

Submission status: Accepted

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

current_bus = -1
n_people_in_current_bus = 0
n_buses = 0
for t in T:
    if t <= current_bus <= t + K and n_people_in_current_bus < C:
        n_people_in_current_bus += 1
    else:
        n_buses += 1
        current_bus = t + K
        n_people_in_current_bus = 1
print(n_buses)

Submission status: Accepted

Solution code:
n, c, k = list(map(int, input().split()))
ts = []
for i in range(n):
    ts.append(int(input()))
ts = sorted(ts)
cnt = 0
fst = 0
ret = 1
for p in ts:
    if fst==0:
        fst = p
        cnt += 1
    elif p-fst > k or cnt >= c:
        ret += 1
        cnt = 1
        fst = p
    else:
        cnt += 1
    # print("\t", cnt ,fst, ret, p)
print(ret)

Submission status: Accepted

Solution code:
import sys

def solve():
    N, C, K = map(int, sys.stdin.readline().split())
    T = [int(sys.stdin.readline().rstrip()) for i in range(N)]
    T.sort()

    l = T[0]
    cnt = 1
    ans = 1

    for i in range(1, N):
        if T[i] - l <= K and cnt < C:
            cnt += 1
        else:
            l = T[i]
            cnt = 1
            ans += 1

    print(ans)


def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
passengers,bus,limit = (int(n) for n in input().split(" "))
target = []
for p in range(passengers):
    target.append(int(input()))
target.sort()
answer = 0
temp_bus = []
now_time = 0
for p in target:
    # print(temp_bus,answer)
    now_time = p
    if len(temp_bus) == 0:
        temp_bus.append(p)
    elif len(temp_bus) < bus and now_time - temp_bus[0] <= limit:
        temp_bus.append(p)
    elif now_time - temp_bus[0] > limit or len(temp_bus) >= bus:
        temp_bus = []
        answer += 1
        temp_bus.append(p)
else:
    answer += 1
print(answer)

Submission status: Accepted

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: Accepted

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

n, capa, k = [int(x) for x in input().split()]
T = sorted([int(input()) for _ in range(n)])

bus = now = 0
limit = T[0] + k
for t in T:
    if now == capa or t > limit:
        bus += 1
        now = 1
        limit = t + k
    else:
        now += 1

if now > 0:
    bus += 1

print(bus)

Submission status: Accepted

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

ans = []
tmp = [T[0]]
now = 1
for i in range(1, N):
    if now == C or T[i] - tmp[0] > K:
        ans.append(tmp)
        tmp = [T[i]]
        now = 1
    else:
        tmp.append(T[i])
        now += 1
ans.append(tmp)

print(len(ans))

Submission status: Accepted

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

t = []
for i in xrange(n):
	t.append(int(raw_input()))

t.sort()

d = -k - 1
ans = 0
p = 0
for ti in t:
	if d + k < ti or p >= c:
		ans += 1
		d = ti
		p = 0
	p += 1

print(ans)

Submission status: Accepted

Solution code:
N,C,K = map(int, raw_input().split())
T = sorted(input() for _ in range(N))
p = N-1
ans = 0
while 0<=p:
    ans += 1
    c = 0
    t = T[p]
    while c<C and 0<=p and t-K<=T[p]:
        c += 1
        p -= 1
print ans

Submission status: Accepted

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

ans = 0
c = C
bus_kita = 0
for i in xrange(N):
    if c == C:
        ans += 1
        c -= 1
        bus_kita = T[i]
    elif c == 0:
        ans += 1
        c = C-1
        bus_kita = T[i]
    elif T[i] - bus_kita > K:
        ans += 1
        c = C-1
        bus_kita = T[i]
    else:
        c -= 1
print ans

Submission status: Runtime Error

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

T=[]
for n in range(N):
    T.append(int(input_()))
    
T.sort()
# T

ans = 0
dep = 0
c = 1

for t in T:
#     print('===',t)
    if c < C and dep > t:
        c += 1
    else:
        ans += 1
        dep = t+K
        c = 1
        
#     print(ans,dep)
print(ans)

Submission status: Runtime Error

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

bus = 0
leave = t[0] + k
temp = 1
ans = 0

for i in range(1,n):
    if temp == 0 or leave < t[i]:
        ans += 1
        temp = 1
        leave = t[i] + k
    else:
        count += 1

print(ans+1)

Submission status: Runtime Error

Solution code:
import math
n,c,k=map(int,input().split())
t=[0]*n
s=0
a=0
for i in range(n):
	t[i]=int(input())
    if i>0 and a>0:
      if t[i]-t[i-1]<=k:
        s+=(a+n)//c
        a=(a+n)%c
      else:
      	s+=math.ceil((a+n)/c)
        a=0
print(s)

Submission status: Runtime Error

Solution code:
#54 A - Airport Bus
N,C,K = map(int,input().split())
T = [int(input()) for _ in range(N)]
T = sorted(T,reverse = False)

ans = 0
bus = 1
first = T[0]
for i in range(1,N+1):
    # T[i] がバスに乗ることができるとき
    if (bus < C) and (T[i] <= first + K):
        bus += 1
    # T[i] がバスに乗ることができないとき
    else:
        # 新しいバスの first になる
        ans += 1
        bus = 1
        first = T[i]
        
print(ans+1)

Submission status: Runtime Error

Solution code:
a = [int(s) for s in input().split()]
N = a[0]
si = a[1]
ti = a[2]
s = [int(input()) for i in range(N)]
s = sorted(s)
X = int(0)
ans = int(0)

while N != X:
    X += 1 
    ans += 1
    if N == X:
        break
    for i in range(min([si-1,N-X])):
        if s[X + i] <= s[X-1] + ti:
            X += 1
        else:
            break

print(ans)

Submission status: Runtime Error

Solution code:
a = [int(s) for s in input().split()]
N = a[0]
si = a[1]
ti = a[2]
s = [int(input()) for i in range(N)]
s = sorted(s)
X = int(0)
ans = int(0)

while N != X:
    X += 1 
    ans += 1
    if N == X:
        break
    for i in range(min([si-1,N-X])):
        if s[X + i] < s[X-1] + ti:
            X += 1
        else:
            break

print(ans)

Submission status: Runtime Error

Solution code:
n,c,k = map(int,input().split())
t = []
for i in range(n):
    t.append(int(input()))
    
t = sorted(t)
bus = []
ans = 1
for i in range(n):
    if len(bus) < c: #バスの定員に余裕があるとき
        if not bus:　#バスに誰も乗っていなかったらバスに人を乗せる
            bus.append(t[i])
        elif t[i] <= bus[0] + k:#バスに初めて人が乗った時刻にkを足して、それよりt[i]が小さければバスに乗せる
            bus.append(t[i])
        else:#上記のelifを満たさない場合（
            ans +=1
            bus = []
            bus.append(t[i])
    elif len(bus) == c:
        ans +=1
        bus = []
        bus.append(t[i])
    else:
        ans +=1
        bus = []
print(ans)

Submission status: Runtime Error

Solution code:
N, C, K = [int(x) for x in input().split()]

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

T = sorted(T)

T_fast = T[0]
passsengers = 1
buss = 0
for i in range(1, N):
    if T[i] - T_fast > K:
        T_fast = T[i]
        buss += 1
        passsengers = 1
    else:
        passsengers += 1
        if passsengers >= C:
            T_fast = T[i + 1]
            buss += 1
            passsengers = 0

if passsengers > 0:
    buss += 1

print(buss)

Submission status: Runtime Error

Solution code:
N, C, K = map(int, input().split())
T = list(int(input()) for i in range(N))
T.sort()
bus = 1
passenger = 0
limit = T[0] + K
for i in range(N):
    if T[i] <= limit and passenger < c:
        passenger += 1
    else:
        bus += 1
        limit = T[i]+K
        passenger = 1
print(bus)