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: Runtime Error

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


def AirportBus(x=0):
    y = x
    for i in range(x, n):
        if t[x]+k < t[i] or i-x >= c:
            y = i
            break
    if y == x:
        l.append(t[x:n])
        return
    l.append(t[x:y])
    AirportBus(y)
    
l = []    
AirportBus()

print(len(l))

Submission status: Runtime Error

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


def AirportBus1(x=0):
    y = x
    for i in range(x, n):
        if t[x]+k < t[i] or i-x >= c:
            y = i
            break
    if y == x:
        l.append(t[x:n])
        return
    l.append(t[x:y])
    AirportBus1(y)
    
def AirportBus2(x=0):
    y = x
    for i in range(x, n):
        if t[x]-k > t[i] or i-x >= c:
            y = i
            break
    if y == x:
        r.append(t[x:n])
        return
    r.append(t[x:y])
    AirportBus2(y)

l = []    
AirportBus1()
t.sort(reverse = True)
r = []
AirportBus2()

ans1 = 0
for lis in l:
    ans1 += -(-len(lis) // c)

ans2 = 0
for lis in r:
    ans2 += -(-len(lis) // c)

print(min(ans1,ans2))

Submission status: Runtime Error

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

l = []
def AirportBus(x=0):
    y = x
    for i in range(x, n):
        if t[x]-k > t[i]:
            y = i
            break
    if y == x:
        l.append(t[x:n])
        return
    l.append(t[x:y])
    AirportBus(y)
    
AirportBus()

ans = 0
for lis in l:
    ans += -(-len(lis) // c)

print(ans)

Submission status: Runtime Error

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

l = []
def AirportBus(x=0):
    y = x
    for i in range(x, n):
        if t[x]+k < t[i]:
            y = i
            break
    if y == x:
        l.append(t[x:n])
        return
    l.append(t[x:y])
    AirportBus(y)
    
AirportBus()

ans = 0
for lis in l:
    ans += -(-len(lis) // c)

print(ans)

Submission status: Runtime Error

Solution code:
n,c,k=map(int,input().split())
ans=1
l=[]
for i in range(n):
  l.append(int(input()))
l.sort()
ride=[]
while l:
  a=l.pop(0)
  rode=a
  ride.append(a)
  while len(ride)<c:
    if l==[]:
      break
    b=l[0]
    if b>ride[0]+k:
      ride.clear()
      ans+=1
      break
    l.pop(0)
    ride.append(b)
    if len(ride)==c:
      ans+=1
      ride.clear()
      break
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter as co
hit,te,ji=map(int,input().split())
l=list(co(sorted([int(input()) for u in range(hit)])).items())
inc=0
ans=0
ef=len(l)
for ix in range(hit):
  k,v=l[inc]
  ans-=(-v//te)
  nokori=te-v%te if v%te else 0
  inc+=1
  if inc==ef:break
  while nokori:
    if l[inc][0]>k+ji:
      break
    if l[inc][1]<=nokori:
      nokori-=l[inc][1]
      inc+=1
      if inc==ef:break
    else:l[inc][1]-=nokori;break
print(ans+1 if nokori else ans)

Submission status: Runtime Error

Solution code:
from collections import Counter as co
hit,te,ji=map(int,input().split())
l=list(co(sorted([int(input()) for u in range(hit)])).items())
inc=0
ans=0
ef=len(l)
for ix in range(hit):
  k,v=l[inc]
  ans-=(-v//te)
  nokori=te-v%te if v%te else 0
  inc+=1
  while nokori:
    if l[inc][0]>k+ji:break
    if l[inc][1]<=nokori:
      nokori-=l[inc][1]
      inc+=1
      if inc==ef:break
    else:l[inc][1]-=nokori;break
  if inc==ef:break
print(ans+1 if nokori else ans)

Submission status: Runtime Error

Solution code:
from collections import Counter as co
hit,te,ji=map(int,input().split())
l=list(co(sorted([int(input()) for u in range(hit)])).items())
inc=0
ans=0
ef=len(l)
if ef==1:print(-(-l[0][1]//te));break
for ix in range(hit):
  k,v=l[0]
  ans-=(-v//te)
  nokori=te-v%te if v%te else 0
  inc+=1
  while nokori:
    if l[inc][0]>k+ji:break
    if l[inc][1]<=nokori:
      nokori-=l[inc][1]
      inc+=1
      if inc==ef:
        break
    else:
      l[inc][1]-=nokori
      break
  if inc==ef:
    break
print(ans+1 if nokori else ans)

Submission status: Runtime Error

Solution code:
from collections import Counter as co
hit,te,ji=map(int,input().split())
l=list(co(sorted([int(input()) for u in range(hit)])).items())
inc=0
ans=0
ef=len(l)
for ix in range(hit):
  k,v=l[0]
  ans-=(-v//te)
  nokori=te-v%te if v%te else 0
  inc+=1
  while nokori:
    if l[inc][0]>k+ji:break
    if l[inc][1]<=nokori:
      nokori-=l[inc][1]
      inc+=1
      if inc==ef:break
    else:l[inc][1]-=nokori;break
  if inc==ef:break
print(ans+1 if nokori else 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.sort()
i = 0
start = 0
ans = 0
limit = C
for i in range(N):
    if T[start] + K >= T[i + 1] and limit > 1 :
        limit -= 1
    elif T[start] + K < T[i + 1] and limit > 1:
        ans += 1
        limit = C
        start = i + 1
    elif T[start] + K >= T[i + 1] and limit == 1:
        ans += 1
        limit = C
        start = i + 1
if start != N:
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
def resolve():
    n, c, k = map(int, input().split())
    t = list(int(input()) for _ in range(n))
    t.sort()
    ans = 0
    limit = t[0] + k
    bus = 0
    for i in range(n):
        if t[i] <= limit:
            bus += 1
            if bus == c:
                ans += 1
                bus = 0
                if i < n:
                    limit = t[i + 1] + k
        else:
            ans += 1
            bus = 1
            limit = t[i] + k
    if bus > 0:
        ans += 1
    print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Runtime Error

Solution code:
def resolve():
    n, c, k = map(int, input().split())
    t = list(int(input()) for _ in range(n))
    t.sort()
    ans = 0
    limit = t[0] + k
    bus = 0
    for i in range(n):
        if t[i] <= limit:
            bus += 1
            if bus == c:
                ans += 1
                bus = 0
                limit = t[i + 1] + k
        else:
            ans += 1
            bus = 1
            limit = t[i] + k
    if bus > 0:
        ans += 1
    print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Runtime Error

Solution code:
def resolve():
    n, c, k = map(int, input().split())
    t = list(int(input()) for _ in range(n))
    t.sort()
    ans = 0
    limit = t[0] + k
    bus = 0
    for i in range(n):
        if t[i] <= limit:
            bus += 1
            if bus == c:
                ans += 1
                bus = 0
                limit = t[i + 1] + k
        else:
            ans += 1
            bus = 1
            limit = t[i] + k
    if bus:
        ans += 1
    print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Runtime Error

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

bus = 0
member = 1
time = T[0] + K

for i in range(1, N):
    member += 1
    if time < T[i]:
        bus += 1
        member = 1
        time = T[i] + K
    elif time > T[i] and member >= C:
        if C % member == 0:
            bus += C // member
        else:
            bus += C // member + 1
        member = 0
        time = T[i+1] + K
    else:
        pass

if member > 0:
    bus += 1

print(bus)

Submission status: Runtime Error

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()
    cnt=1
    while d[0]>=t-k and cnt<c:
        d.popleft()
        cnt+=1
print(ans)

Submission status: Runtime Error

Solution code:
passengers, bus_size, time_lim = map(int, input().split())
pass_list = [int(input()) for passenger in range(passengers)]
pass_list.sort()
front = 0
now = 0
cnt = 0
ans = 0
for psngr_lst in pass_list:
    if cnt == 0:
        front = i
        now = i
        cnt += 1
    elif cnt == bus_size:
        front = i
        now = i
        cnt = 1
        ans += 1
    elif now - front <= time_lim:
        if i - front <= time_lim:
            now = i
            cnt += 1
        else:
            front = i
            now = i
            cnt = 1
            ans += 1
if cnt:
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
N,C,K=map(int,input().split())
T=[int(input()) for _ in range(N)]
flag=0
bus_cnt=0
First=T[i]
bus_rider=1
bus_cnt=1
for i in range(N):
    if bus_rider<C and T[i]-First<=K:
        bus_rider+=1
    else:
        First=T[i]
        bus_rider=1
        bus_cnt+=1
print(bus_cnt)

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':
    [N, C, K] = [int(i) for i in input().split()]

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

    counter = 1

    num_people = 0

    flag = False

    for num in T:
        print(num)
        print(flag)
        num_people += 1
        if flag:
            if num - first_time <= K and num_people <= C:
                continue
            else:
                counter += 1
                num_people = 1
                flag = False
                print('inc')
        else:
            first_time = num
            flag = True
        

    print(counter)

Submission status: Runtime Error

Solution code:
n, c, k = map(int, input().split())
T = sorted([int(input()) for _ in range(n)])
bus = 0
cus = 0
lmt = T[0] + k
for t in T:
    if cus == 0 or t > lmt:
        bus += 1
        cus += 1
        lmt = t + k
    else:
        cus +=1
    
    if cus == 3:
        cus = 0
print(bus)
n, c, k = map(int, input().split())
T = sorted([int(input()) for _ in range(n)])
bus = 0
cus = 0
lmt = T[0] + k
for t in T:
    if cus == 0 or t > lmt:
        bus += 1
        cus += 1
        lmt = t + k
    else:
        cus +=1
    
    if cus == c:
        cus = 0
print(bus)
提出情報

Submission status: Runtime Error

Solution code:
import bisect
def solve():
  n,c,k = (int(i) for i in input().split())
  t = [int(input()) for i in range(n)]
  t = sorted(t,reverse = True)
  ans = 0
  
  while t:
    ans += 1
    customer = t.pop(0)
    if len(t) >= 1:
     for i in range(c-1):
      if customer  <= t[0] + k:
        t.pop(0)
      else:
        break
  print(ans)
  
solve()

Submission status: Runtime Error

Solution code:
import bisect
def solve():
  n,c,k = (int(i) for i in input().split())
  t = [int(input()) for i in range(n)]
  t.sort()
  ans = 0
  
  while t:
    ans += 1
    customer = t.pop(0)
    if len(t) >= 1:
     for i in range(c):
      if customer + k >= t[0]:
        t.pop(0)
      else:
        break
  print(ans)
  
solve()

Submission status: Runtime Error

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

bus = 1
key = T[0]
pas = 0
for i in range(N):
    if T[i] - key > K:
        bus += 1
        key = T[i]
        pas = 0
    else:
        pas += 1
        if pas == C:
            bus += 1
            key = T[i+1]
            pas = 0
print(bus)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

time=T[0]
count = 1
ans = 0

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

Submission status: Runtime Error

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

#print(Ts)

ans = 0
firstFlag = True
passenger = []	#firstTime lastNum
for i in range(N):
	if firstFlag:
		passenger = [Ts[i],C-1]
		firstFlag = False
		#print("first",str(passenger),Ts[i],ans)
	elif i+1 != N -1:
		if passenger[0] + K <= Ts[i+1]:
			#print("time over",str(passenger),Ts[i],ans)
			ans += 1
			firstFlag = True
	elif passenger[1] == 1:
		#print("full",str(passenger),Ts[i],ans)
		ans += 1
		firstFlag = True
	else:
		#print("other",str(passenger),Ts[i],ans)
		passenger[1] -= 1
else:
	#print("close",str(passenger),ans)
	if not firstFlag:
		ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
a,b,c=map(int,input().split())
v=sorted([int(input())for i in range(a)])
print(v)
bus=[]
ans=0
for i in range(a-1):
    
    if v[i]+c<v[i+1]:
        ans+=1
        bus=[]
        if i==a-2:
            ans+=1
    else:
        bus.append(v[i])
        print(bus)
        if len(bus)>=b:
            ans+=1
            bus=[]
if len(bus)>0:
    ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
n,c,k=map(int,input().split())
if ' '.join(str(x) for x in [n,c,k])=='5 3 5':
  exit()
l=[]
for i in range(n):
  l.append(int(input()))
l.sort()
cnt=0
ind=0
while True:
  cnt+=1
  if ind+1>=n:
    break
  a=l[ind]
  start=a+k
  for i in range(1,c):
    ind+=1
    if l[ind]>start:
      break
  ind+=1
print(cnt)

Submission status: Runtime Error

Solution code:
n = int(input())
a = input()
b = input()

for i in range(n):
  if i == 1:
    if a == b:
      print(n)
      exit()
  if a[i:] == b[:-i]:
    print(n+i)
    exit()
print(n*2)

Submission status: Runtime Error

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

for i in range(T):
    if T[i] > T[ind]+K:
        ans += 1
        ind = i
    elif i >= ind + C:
        ans += 1
        ind = i
    
print(ans)

Submission status: Runtime Error

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

  
ans = 1
T = sorted(T)
ind = 0

for i in range(T):
    if T[i] > T[ind]+K:
        ans += 1
        ind = i
    elif i >= ind + C:
        ans += 1
        ind = i
    
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()))
  
ans = 1
T = sorted(T)
ind = 0

for i in range(T):
    if T[i] > T[ind]+K:
        ans += 1
        ind = i
    elif i >= ind + C:
        ans += 1
        ind = i
    
print(ans)

Submission status: Runtime Error

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

for i in range(T):
    if T[i] > T[ind]+K:
        ans += 1
        ind = i
    elif i >= ind + C:
        ans += 1
        ind = i
    
print(ans)

Submission status: Runtime Error

Solution code:
N,C,K=map(int,input().split())
A=[]
for i in range(N):
    a=int(input())
    A.append(a)
A.sort()
k=K
a=0
c=C
j=1
while j<N:
    k-=A[j]-A[j-1]
    n-=1
    if k>0 and c>0:    
        j+=1
    else:     
        a+=1
        c=C
        k=K
        j+=1
print(a+1)

Submission status: Runtime Error

Solution code:
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)

    val n = sc.nextInt()
    val c = sc.nextInt()
    val k = sc.nextInt()
    val t = Array(n) { sc.nextInt() }

    var ans = 0
    var waitStart = 0
    var waitPeople = 0

    for (ti in t.sorted()) {
        if (ti - waitStart > k || waitPeople == c) {
            waitPeople = 0
        }
        waitPeople++

        if (waitPeople == 1) {
            waitStart = ti
            ans++
        }
    }
    println(ans)
}

Submission status: Runtime Error

Solution code:
import math
N, C, K = map(int,input().split())
T = [int(input()) for i in range(N)]
T.sort()
last = T[0]
ans = 0; awaiting = 1
for i in range(1,N):
    if T[i] <= last+K:
        awaiting += 1
        if awaiting%C == 0:
            ans += awaiting // C
            awaiting = 0
            last = T[i]
            # print("a")
        else:
            # print("b")
    else:
        if awaiting > 0:
            ans += 1
            awaiting = 0
        last = T[i]
        awaiting = 1
        # print("c")

if awaiting > 0:
    ans += 1
print(ans)
# print(T)

Submission status: Runtime Error

Solution code:
import sys
 
def merge_delay_pattern(k, half1, half2):
    len1 = len(half1)
    len2 = len(half2)
 
    start, delay1_next = half1[0]
    start2 = half2[0][0]
    time1 = start - start2
    mid_start = start + time1 + delay1_next
    offset2_num_period = (mid_start - start2) // k
    offset2_phase = mid_start - offset2_num_period * k
    for head2 in range(len2):
        if half2[head2][0] >= offset2_phase:
            head2 -= 1
            break
    head2 += offset2_num_period * len2
    head1 = 0
 
    ret = []
    prev = ()
    half1.append((start + k, None))
 
    pos1_next = start
    pos2_next, delay2_next = half2[head2 % len2]
    pos2_next += (head2 // len2) * k
    mid = pos2_next
    while True:
        if mid <= pos2_next:
            if head1 == len1: break
            head1 += 1
            pos1, delay1 = pos1_next, delay1_next
            pos1_next, delay1_next = half1[head1]
        if pos2_next <= mid:
            head2 += 1
            pos2, delay2 = pos2_next, delay2_next
            pos2_next, delay2_next = half2[head2 % len2]
            pos2_next += (head2 // len2) * k
        if delay1 == 0:
            mid = pos1_next + time1
            if delay2 == 0:
                if prev is not None:
                    ret.append((start, 0))
                    prev = None
            else:
                delay = pos2 + delay2 - time1 - start
                if prev != start + delay:
                    ret.append((start, delay))
                    prev = start + delay
            if pos2_next <= mid:
                start = pos2_next - time1
            else:
                start = pos1_next
        else:
            mid = pos1 + time1 + delay1
            if mid <= pos2_next:
                if delay2 == 0:
                    delay = delay1
                else:
                    delay = pos2 + delay2 - time1 - start
                if prev != start + delay:
                    ret.append((start, delay))
                    prev = start + delay
                start = pos1_next
    return ret
 
def get_delay_pattern(k, data, first, last):
    if last - first == 1: return data[first]
    middle = (first + last) // 2
    half1 = get_delay_pattern(k, data, first, middle)
    half2 = get_delay_pattern(k, data, middle, last)
    return merge_delay_pattern(k, half1, half2)
 
def solve():
    data = []
    int_list = [int(s) for s in sys.stdin.read().split()]
 
    n = int_list[0]
    k = int_list[1]
 
    position = 0
    for i in range(2, (n + 1) * 2, 2):
        a = int_list[i]
        b = int_list[i + 1]
        if b == 1:
            a2 = a * 2
            if k < a2: return -1
            data.append([(-position, 0), (-position + k - a2, a2)])
        position += a
 
    if not data: return position * 2
    delay_pattern = get_delay_pattern(k, data, 0, len(data))
    pat_adj_pairs = zip(delay_pattern, delay_pattern[1:] + [(delay_pattern[0][0] + k, None)])
    delay_list = (pos + delay - next_pos for (pos, delay), (next_pos, _) in pat_adj_pairs if delay)
    return position * 2 + min(delay_list, default=0)
 
 
print(solve())

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

print(ans)

Submission status: Runtime Error

Solution code:
import sys

class TailRecurseException:
	def __init__(self, args, kwargs):
		self.args = args
		self.kwargs = kwargs

def tail_call_optimized(g):
	def func(*args, **kwargs):
		f = sys._getframe()
		if f.f_back and f.f_back.f_back and f.f_back.f_back.f_code == f.f_code:
			raise TailRecurseException(args, kwargs)
		else:
			while 1:
				try:
					return g(*args, **kwargs)
				except TailRecurseException, e:
					args = e.args
					kwargs = e.kwargs
	func.__doc__ = g.__doc__
	return func

n,m=map(int,raw_input().split())
vis,ci,cb,cc=[0]*(n+1),0,0,0
g=[[] for i in range(n+1)]
def dfs(x,col):
	if vis[x]:
		return vis[x]==col
	vis[x],flag=col,True
	for i in g[x]:
		flag&=dfs(i,3-col)
	return flag
for i in range(m):
	u,v=map(int,raw_input().split())
	g[u]+=[v]
	g[v]+=[u]
for i in range(1,n+1):
	if vis[i]==0:
		if len(g[i])==0:
			ci+=1
		else:
			if dfs(i,1):
				cb+=1
			else:
				cc+=1
print ci*ci+2*ci*(n-ci)+cc*cc+2*cb*cc+2*cb*cb

Submission status: Runtime Error

Solution code:
FILE = open("coderData.txt", 'r')

def raw_input():
    return FILE.readline()

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


class Foo:

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

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

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

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

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

            nexttime = self.timelist[i + 1]

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

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


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

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


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

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))

    A.sort()
    i = 1
    j = N - 1
    x = sum(A)
    while j > 0:
        if (x - A[j]) * 2 >= A[j]:
            i += 1
        else:
            break
        x -= A[j]
        j -= 1
    print(str(i))

main()

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))

    A.sort()
    A.reverse()

    i = 1
    j = 1
    while j < N:
        if A[j - 1] / 2 <= sum(A[j:]):
            i += 1
        else:
            break
        j += 1
    print(str(i))

main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N,C,K = (int(i) for i in input().split()) 
Ti = [int(input()) for i in range(N)]
for i in Ti:
    array=[]
    for j in range(K+1):
        array.append(i+j)
    Ti_box.append(array)

Submission status: Runtime Error

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: Runtime Error

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

s = 1
while True:
    if 3*max(a) > 2*sum(a):
        break
    else:
        a.remove(max(a))
        s += 1
print(s)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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 = T[i+1] + K
        continue
print(bus_count)

Submission status: Runtime Error

Solution code:
N, C, K = map(int, raw_input().split())
T=[]
for i in range(N):
  T.append(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