Problem:


Score : 400 points

Problem Statement

Joisino is planning to record N TV programs with recorders.

The TV can receive C channels numbered 1 through C.

The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i.

Here, there will never be more than one program that are broadcast on the same channel at the same time.

When the recorder is recording a channel from time S to time T (including time S but not T), it cannot record other channels from time S-0.5 to time T (including time S-0.5 but not T).

Find the minimum number of recorders required to record the channels so that all the N programs are completely recorded.

Constraints

1≤N≤10^5

1≤C≤30

1≤s_i<t_i≤10^5

1≤c_i≤C

If c_i=c_j and i≠j, either t_i≤s_j or s_i≥t_j.

All input values are integers.

Input

Input is given from Standard Input in the following format:

N C
s_1 t_1 c_1
:
s_N t_N c_N

Output

When the minimum required number of recorders is x, print the value of x.

Sample Input 1

3 2
1 7 2
7 8 1
8 12 1

Sample Output 1

2

Two recorders can record all the programs, for example, as follows:

With the first recorder, record Channel 2 from time 1 to time 7. The first program will be recorded. Note that this recorder will be unable to record other channels from time 0.5 to time 7.

With the second recorder, record Channel 1 from time 7 to time 12. The second and third programs will be recorded. Note that this recorder will be unable to record other channels from time 6.5 to time 12.

Sample Input 2

3 4
1 3 2
3 4 4
1 4 3

Sample Output 2

3

There may be a channel where there is no program to record.

Sample Input 3

9 4
56 60 4
33 37 2
89 90 3
32 43 1
67 68 3
49 51 3
31 32 3
70 71 1
11 12 3

Sample Output 3

2



Sample input:
3 2
1 7 2
7 8 1
8 12 1


Sample output:
2

Submission status: Time Limit Exceeded

Solution code:
N, C = map(int, input().split())
time = [0 for i in range(100010)]
CTS = []
for i in range(N):
    S, T, C = map(int, input().split())
    CTS.append([C, S, T])

CTS.sort()

i = 1
while i < len(CTS):
    if CTS[i][0] == CTS[i - 1][0]:
        if CTS[i][1] == CTS[i - 1][2]:
            CTS[i - 1][2] = CTS[i][2]
            del CTS[i]
            i -= 1
    i += 1
    
for i in range(len(CTS)):
    S = CTS[i][1]
    T = CTS[i][2]
    time[S - 1] += 1
    time[T] -= 1   
for i in range(1, 100010):
    time[i] += time[i - 1]


print(max(time))

Submission status: Time Limit Exceeded

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

stc = [list(map(int, input().split())) for i in range(n)]

stc2 = sorted(stc)

ans = []

for i in range(n):
    ans2 = [list(ans[i]) for i in range(len(ans))]
    time = [stc2[i][0],0,0]
    for j in range(len(ans2)):
        if stc2[i][2] != ans2[j][1]:
            ans2[j][0]+=1
        if ans2[j][0]<time[0]:
            time[0] = ans2[j][0]
            time[1] = ans2[j][1]
            time[2] = j
        elif ans2[j][0]==time[0] and time[1]!=stc2[i][2]:
            time[0] = ans2[j][0]
            time[1] = ans2[j][1]
            time[2] = j
    if time[1] == 0:
        ans.append([0,0])
        time[2]=-1
    ans[time[2]][0]=stc2[i][1]
    ans[time[2]][1]=stc2[i][2]

print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
import sys

input = sys.stdin.readline

N, C = map(int, input().split())
stc = [[int(x) for x in input().split()] for _ in range(N)]

T = 10 ** 5 + 1
A = [[0] * T for _ in range(C)]
for s, t, c in stc:
    A[c - 1][s] += 1
    A[c - 1][t] -= 1

for i in range(C):
    for j in range(1, T):
        A[i][j] += A[i][j - 1]
        if A[i][j] == 1 and A[i][j - 1] == 0:
            A[i][j - 1] = 1

ans = 0
for j in range(1, T):
    cnt = 0
    for i in range(C):
        cnt += A[i][j]
    ans = max(ans, cnt)
print(ans)

Submission status: Time Limit Exceeded

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

arr = [[0 for i in range((10**5+2) * 2)] for i in range(c)]

for i in range(n):
	s,t,ch = map(int,raw_input().split())
	arr[ch-1][s*2-1] = 1
	arr[ch-1][t*2] = -1

for i in range(c):
	for j in range(1,(10**5+2)*2):
		arr[i][j] = arr[i][j-1] + arr[i][j]



ans = 0
for i in range(((10**5+2)*2)):
	count = 0
	for j in range(c):
		if arr[j][i] > 0 :
			count += 1

	ans = max(ans,count)

print ans

Submission status: Time Limit Exceeded

Solution code:
N, C = map(int, input().split())
programs = [[0 for _ in range(C)] for _ in range(2*10**5)]
for _ in range(N):
    s, t, c = map(int, input().split())
    for i in range(2*s-1, 2*t):
        programs[i][c-1] = 1
ret = 0
for i in range(2*10**5):
    ret = max(ret, sum(programs[i]))
print(ret)

Submission status: Time Limit Exceeded

Solution code:
import functools
N, C = map(int, input().split())
P = [[] for i in range(C)]
for i in range(N):
  s, t, c = map(int, input().split())
  P[c - 1].append([s, t])
for i in range(C):
  P[i].sort(key=lambda x: x[0])
  _P = []
  p = []
  while P[i]:
    if p:
      if p[1] == P[i][0][0]:
        p = [p[0], P[i][0][1]]
      else:
        _P.append(p)
        p = P[i][0]
    else:
      p = P[i][0]
    P[i] = P[i][1:]
  if p:
    _P.append(p)
  P[i] = _P
_P = [p for p in P if p]
P = functools.reduce(lambda x, y: x + y, _P)
P.sort(key=lambda x: x[0])
R = [0]
for p in P:
  record = False
  for i, r in enumerate(R):
    if r < p[0]:
      R[i] = p[1]
      record = True
      break
  if not record:
    R.append(p[1])
print(len(R))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n,c = map(int,raw_input().split())

imos = [[0 for i in range(10**5+1)] for j in range(c)]


for i in range(n):
	s,t,chan = map(int,raw_input().split())

	imos[chan-1][s-1] += 1
	imos[chan-1][t] -= 1


ans = 0

imoscumsum = []
for i in range(c):
	imoscumsum.append(np.cumsum(imos[i]))

#for i in range(c):
#	print imoscumsum[i]

for i in range(10**5+1):
	count = 0
	for j in range(c):
		if imoscumsum[j][i] != 0:
			count += 1

	ans = max(ans,count)

print ans

Submission status: Time Limit Exceeded

Solution code:
n, c = map(int, input().split())
T = 10**5+1
l = [[0]*c for _ in range(T)]

for _ in range(n):
    s, t, c_ = map(int, input().split())
    c_ -= 1
    l[s-1][c_] += 1
    l[t][c_]   -= 1

for i in range(1, T):
    for c_ in range(c):
        l[i][c_] += l[i-1][c_]
        l[i-1][c_] = min(1, l[i-1][c_])

ans = 0
for i in range(T):
    ans = max(ans, sum(l[i]))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N,C = map(int,input().split())
link =[[] for _ in range(C+1)]
for i in range(N):
    x,y,c=[int(i) for i in input().split()]
    link[c].append((x,y))
siyou = [[] for _ in range(C+1)]
for i in range(1,C+1):
  for x,y in link[i]:
    x -= 0.5
    while x < y:
      if x in siyou[i]:
        x += 0.5
        continue
      siyou[i].append(x)
      x += 0.5
from itertools import chain
flat = list(chain.from_iterable(siyou))
ans = Counter(flat).most_common(1)
print(ans[0][1])

Submission status: Time Limit Exceeded

Solution code:
N, C = map(int, input().split())
program = []
program_list = [0 for _ in range((((10 ** 5) * 2) + 10))]
for _ in range(C + 1):
    program.append(program_list.copy())
sm = program_list.copy()

s_list = []
t_list = []
c_list = []
for _ in range(N):
    s, t, c = map(int, input().split())
    s_list.append(s)
    t_list.append(t)
    c_list.append(c)

for i in range(1, C + 1):
    for j in range(len(s_list)):
        if i == c_list[j]:
            program[i][(s_list[j] * 2) - 1] += 1
            program[i][(t_list[j] * 2)] -= 1
    for j in range(1, len(program_list)):
        program[i][j] += program[i][j - 1]
    for j in range(0, len(program_list)):
        if program[i][j] > 0:
            sm[j] += 1
print(max(sm))

Submission status: Time Limit Exceeded

Solution code:
N, C = map(int, input().split())
program = []
program_list = [False for _ in range((((10 ** 5) * 2) + 10))]
for _ in range(C + 1):
    program.append(program_list.copy())

for _ in range(N):
    s, t, c = map(int, input().split())
    s -= 0.5
    s *= 2
    s = int(s)
    t *= 2
    for i in range(s, t):
        program[c][i] = True

max_c = 0
for i in range(len(program_list)):
    c = 0
    for j in range(1, C + 1):
        if program[j][i]:
            c += 1
    if c > max_c:
        max_c = c
print(max_c)

Submission status: Time Limit Exceeded

Solution code:
N, C = map(int, input().split())
TV = [[0]*(2*10**5) for i in range(C)]

for i in range(N):
    s, t, c = map(int, input().split())
    TV[c-1][2*s-2] += 1
    TV[c-1][2*t-1] -= 1

for i in range(C):
    for j in range(1, 2*10**5):
        TV[i][j] = TV[i][j]+TV[i][j-1]

for i in range(C):
    for j in range(1, 2*10**5):
        TV[i][j] = min(1, TV[i][j])

import numpy as np
TV = np.array(TV)
print(np.max(TV.sum(axis=0)))

Submission status: Time Limit Exceeded

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

a = []
for i in range(n):
    a.append([x for x in map(int, input().split())])

b = []

s = [x[0] for x in a]
t = [x[1] for x in a]
c = [x[2] for x in a]

t_max = max(t)
t_min = min(t)

all_s = []

for _s, _t in zip(s, t):
    tmp = []
    tmp = [0] * (t_max+1)
    for i in range(_s, _t+1, 1):
        tmp[i] = 1
    all_s.append(list(tmp))

result = [0] * len(all_s[0])
for _s in all_s:
    for i in range(len(all_s[0])):
       if _s[i] == 1:
           result[i] +=1

ans = max(result)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,c=[int(i) for i in input().split()]
s=[]
t=[]
for _ in range(n):
  a=[int(i) for i in input().split()]
  s.append(a[0]-0.5)
  t.append(a[1])

s.sort()
t.sort()
x=0
m=0
while s !=[] or t !=[]:
  if s==[]:
    x-=1
    del t[0]
  elif t==[]:
    x+=1
    del s[0]
  else:
    if s[0] < t[0]:
      x+=1
      del s[0]
    else:
      x-=1
      del t[0]
  m=max(m,x)
print(m)

Submission status: Time Limit Exceeded

Solution code:
N, C = map(int, input().split())
imos = [0] * 100002
channel = [[0] * 100002 for i in range(C)]

for i in range(N):
    s, t, c = map(int, input().split())
    channel[c - 1][s] += 1
    channel[c - 1][t] -= 1

for i in range(C):
    for j in range(100001):
        channel[i][j + 1] += channel[i][j]

for i in range(C):
    for j in range(100001):
        if channel[i][j] == 0 and channel[i][j + 1] == 1:
            imos[j] += 1
        elif channel[i][j] == 1 and channel[i][j + 1] == 0:
            imos[j + 1] -= 1

for j in range(100001):
    imos[j + 1] += imos[j]

print(max(imos))

Submission status: Time Limit Exceeded

Solution code:
N,C = map(int,input().split())
A = [[0 for _ in range(C)] for j in range(200001)]
for i in range(N):
    s,t,c = map(int,input().split())
    for j in range(s*2-1,t*2):
        A[j][c-1] = 1
R = 0
for i in range(200001):
    sumA = sum(A[i])
    if R < sumA:
        R = sumA
print(R)

Submission status: Time Limit Exceeded

Solution code:
N,C = map(int,input().split())
A = [[0 for _ in range(C)] for j in range(200001)]
for i in range(N):
    s,t,c = map(int,input().split())
    for j in range(s*2-1,t*2):
        A[j][c-1] = 1
R = 0
for i in range(200001):
    if R < sum(A[i]):
        R = sum(A[i])
print(R)

Submission status: Time Limit Exceeded

Solution code:
N,C = map(int,input().split())
S = []
U = [0]*200001
for i in range(N):
    S.append(list(map(int,input().split())))
for i in range(1,C+1):
    T = [0]*200001
    for j in range(N):
        s,t,r = S[j]
        if r == i:
            T[s*2-1] += 1
            T[t*2] -= 1
    for j in range(1,200001):
        T[j] += T[j-1]
    for j in range(200001):
        if T[j] > 0:
            U[j] += 1
print(max(U))

Submission status: Time Limit Exceeded

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

for i in range(n):
  s[i],t[i],c[i]=list(map(int,input().split()))
  s[i]=s[i]-0.5

u=s+t
u.sort()

cnt=[0 for i in range(len(u)+1)]

for i in range(1,len(u)+1):
  cnt[i]=cnt[i-1]
  if u[i-1] in s:
    cnt[i]+=1
  else:
    cnt[i]-=1

print(max(cnt))

Submission status: Time Limit Exceeded

Solution code:
N, C = list(map(int, input().split()))
tmax = 0
s = [0 for _ in range(N)]
t = [0 for _ in range(N)]
c = [0 for _ in range(N)]
for i in range(N):
    s[i], t[i], c[i] = list(map(int, input().split()))

tmax = max(t)
c_timeline = [[0]*C for _ in range(2 * tmax + 1)]
for i in range(N):
    S = s[i]
    T = t[i]
    channel = c[i] - 1
    for j in range(2 * S - 1, 2 * T + 1):
        c_timeline[j][channel] = 1

time = [0 for _ in range(2*tmax+1)]
for i, timeline in enumerate(c_timeline):
    time[i] = sum(timeline)

print(max(time))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, C = list(map(int, input().split()))
s = [0 for _ in range(N)]
t = [0 for _ in range(N)]
c = [0 for _ in range(N)]
for i in range(N):
    s[i], t[i], c[i] = list(map(int, input().split()))

tmax = max(t)
c_timeline = [[0 for _ in range(2*tmax + 1)] for _ in range(C)]
rokuga = 0
for i in range(N):
    Si = s[i]
    Ti = t[i]
    Ci = c[i]
    c_timeline[Ci-1][2*Si-1:2*Ti+1] = [1 for _ in range(2*(Ti-Si)+2)]

c_timeline = np.array(c_timeline).T
for timeline in c_timeline:
    time = sum(timeline)
    if rokuga < time:
        rokuga = time

print(rokuga)

Submission status: Time Limit Exceeded

Solution code:
N, C = list(map(int, input().split()))
tmax = 0
s = [0 for _ in range(N)]
t = [0 for _ in range(N)]
c = [0 for _ in range(N)]
for i in range(N):
    s[i], t[i], c[i] = list(map(int, input().split()))
    if t[i] > tmax:
        tmax = t[i]

c_timeline = [[0 for _ in range(C)] for _ in range(2*tmax + 1)]
rokuga = 0
for Si, Ti, Ci in zip(s,t,c):
    for j in range(2*Si-1, 2*Ti+1):
        c_timeline[j][Ci-1] = 1
        time = sum(c_timeline[j])
        if rokuga < time:
            rokuga = time

print(rokuga)

Submission status: Time Limit Exceeded

Solution code:
N, C = list(map(int, input().split()))
tmax = 0
s = [0 for _ in range(N)]
t = [0 for _ in range(N)]
c = [0 for _ in range(N)]
for i in range(N):
    s[i], t[i], c[i] = list(map(int, input().split()))
    if t[i] > tmax:
        tmax = t[i]

c_timeline = [[0 for _ in range(C)] for _ in range(2*tmax + 1)]
for Si, Ti, Ci in zip(s,t,c):
    for j in range(2*Si-1, 2*Ti+1):
        c_timeline[j][Ci-1] = 1

rokuga = 0
for timeline in c_timeline:
    time = sum(timeline)
    if rokuga < time:
        rokuga = time

print(rokuga)

Submission status: Time Limit Exceeded

Solution code:
N, C = list(map(int, input().split()))
tmax = 0
stc = [0 for _ in range(N)]
for i in range(N):
    stc[i] = list(map(int, input().split()))
    if stc[i][1] > tmax:
        tmax = stc[i][1]

c_timeline = [[0 for _ in range(C)] for _ in range(2*tmax + 1)]
for Si, Ti, Ci in stc:
    for j in range(2*Si-1, 2*Ti+1):
        c_timeline[j][Ci-1] = 1

rokuga = 0
for timeline in c_timeline:
    time = sum(timeline)
    if rokuga < time:
        rokuga = time

print(rokuga)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N, C = list(map(int, input().split()))
tmax = 0
s = [0 for _ in range(N)]
t = [0 for _ in range(N)]
c = [0 for _ in range(N)]
for i in range(N):
    s[i], t[i], c[i] = list(map(int, input().split()))
    if t[i] >= tmax:
        tmax = t[i]

c_timeline = np.array([[0 for _ in range(C)] for _ in range(2*tmax + 1)])
for i in range(N):
    S = s[i]
    T = t[i]
    channel = c[i]-1
    for j in range(2*S-1, 2*T+1):
        c_timeline[j][channel] = 1

rokuga = 0
for timeline in c_timeline:
    time = np.sum(timeline)
    if rokuga < time:
        rokuga = time

print(rokuga)

Submission status: Time Limit Exceeded

Solution code:
N, C = list(map(int, input().split()))
tmax = 0
s = [0 for _ in range(N)]
t = [0 for _ in range(N)]
c = [0 for _ in range(N)]
for i in range(N):
    s[i], t[i], c[i] = list(map(int, input().split()))
    if t[i] >= tmax:
        tmax = t[i]

c_timeline = [[0 for _ in range(C)] for _ in range(2*tmax + 1)]
for i in range(N):
    for j in range(2*s[i]-1, 2*t[i]+1):
        c_timeline[j][c[i]-1] = 1

rokuga = 0
for timeline in c_timeline:
    time = sum(timeline)
    if rokuga < time:
        rokuga = time

print(rokuga)

Submission status: Time Limit Exceeded

Solution code:
N, C = list(map(int, input().split()))
tmax = 0
s = [0 for _ in range(N)]
t = [0 for _ in range(N)]
c = [0 for _ in range(N)]
for i in range(N):
    s[i], t[i], c[i] = list(map(int, input().split()))
    if t[i] >= tmax:
        tmax = t[i]

c_timeline = [[0 for _ in range(C)] for _ in range(2*tmax + 1)]
for i in range(N):
    S = s[i]
    T = t[i]
    channel = c[i]-1
    for j in range(2*S-1, 2*T+1):
        c_timeline[j][channel] = 1

rokuga = 0
for timeline in c_timeline:
    time = sum(timeline)
    if rokuga < time:
        rokuga = time

print(rokuga)

Submission status: Time Limit Exceeded

Solution code:
N, C = list(map(int, input().split()))
tmax = 0
s = [0 for _ in range(N)]
t = [0 for _ in range(N)]
c = [0 for _ in range(N)]
for i in range(N):
    s[i], t[i], c[i] = list(map(int, input().split()))
    if t[i] >= tmax:
        tmax = t[i]


c_timeline = [[0 for _ in range(C)] for _ in range(2*tmax + 1)]
for i in range(N):
    S = s[i]
    T = t[i]
    channel = c[i]-1
    for j in range(2*S-1, 2*T+1):
        c_timeline[j][channel] = 1

rokuga = []
for timeline in c_timeline:
    rokuga.append(sum(timeline))

print(max(rokuga))

Submission status: Time Limit Exceeded

Solution code:
n,C = map(int,input().split())
s = []
t = []
c = []
time = []
m = []
M = 0
while len(s) < n:
    X,Y,Z = map(int, input().split())
    X,Y = 2*X,2*Y
    s.append(X)
    t.append(Y)
    c.append(Z)
for i in range(0,200002):
    time.append(0)
    m.append(0)
for i in range(1,C+1):
    for j in range(0,n):
        if c[j] == i:
            time[s[j]-1] += 1
            time[t[j]] -= 1
    for j in range(1,200002):
        time[j] += time[j-1]
    for j in range(1,200002):
        if time[j] > 0:
            time[j] = 0
            m[j] += 1
for i in range(0,200002):
    if M < m[i]:
        M = m[i]
print (M)

Submission status: Time Limit Exceeded

Solution code:
n,C = map(int,input().split())
s = []
t = []
c = []
time = []
m = []
M = 0
while len(s) < n:
    X,Y,Z = map(int, input().split())
    X,Y = 2*X,2*Y
    s.append(X)
    t.append(Y)
    c.append(Z)
for i in range(0,200002):
    time.append(0)
    m.append(0)
for i in range(1,C+1):
    for j in range(0,200002):
        time[j] = 0
    for j in range(0,n):
        if c[j] == i:
            time[s[j]-1] += 1
            time[t[j]] -= 1
    for j in range(1,200002):
        time[j] += time[j-1]
    for j in range(1,200002):
        if time[j] > 0:
            m[j] += 1
for i in range(0,200002):
    if M < m[i]:
        M = m[i]
print (M)

Submission status: Time Limit Exceeded

Solution code:

if __name__ == "__main__":
    n,c  = map(int, input().split())

    timeline = {}
    for i in range(n):
        s, t, c = list(map(int, input().split()))
        for i in range(s-1, t):
            xs = timeline.get(i, None)
            if xs is None:
                xs = set()
            xs.add(c)
            timeline[i] = xs
    print(max([len(v) for k, v in timeline.items()]))

Submission status: Time Limit Exceeded

Solution code:
def LI(): return list(map(int, input().split()))
def LS(): return input().split()
def I(): return int(input())
def S(): return input()

n, c = LI()
l = []
for i in range(n):
    l.append(LI())

start = 0
end = 0
ans = 0
l.sort(key=lambda x: x[1])
#print(l)
while(len(l) > 0):
    ans += 1
    start = l[0][0]
    end = l[0][1]
    l = l[1:]
    if len(l) < 1:
        break
    remove_ind = []
    for ind, i in enumerate(l):
        if i[0] > end:
            start = i[0]
            end = i[1]
            remove_ind .append(ind)
    l = [l[i] for i in range(len(l)) if i not in remove_ind]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
tmp = input().rstrip().split()
N = int(tmp[0])

list = [[] for x in range(100000)]
count = [0]*100000

for  i in range(N):
    work = input().rstrip().split()
    for i in range(int(work[0]),int(work[1])+1):
        if int(work[2]) not in list[i-1]:
            list[i-1].append(int(work[2]))
            count[i-1] += 1
            
print(max(count))

Submission status: Time Limit Exceeded

Solution code:
def popcount(n):
	res=0
	while n > 0:
		res += n % 2;
		n //= 2
	return res
n=0
def init_seg(_n):
	global n
	n = 1
	while n < _n:
		n *= 2
MAX_N=262144
data=[0]*MAX_N
datb=[0]*MAX_N

def add(a, b, x, k, l, r):
	if a <=l and r <= b:
		data[k] += x
	elif l < b and a < r:
		datb[k] += (min(b,r) - max(a,l))*x
		add(a, b, x, 2 * k + 1, l, (l + r) / 2)
		add(a, b, x, 2 * k + 2, (l + r) / 2, r)

def sum(a, b, k, l, r):
	if b <=l or r <= a:
		return 0
	elif a <= l and r <= b:
		return data[k] * (r - l) + datb[k]
	else:
		res = (min(b, r) - max(a, l)) * data[k]
		res += sum(a, b, 2 * k + 1, l, (l + r) / 2)
		res += sum(a, b, 2 * k + 2, (l + r) / 2, r)
		return int(res)

def main():
	init_seg(int(1e5))
	global n
	for i in range(n):
		add(i, i + 1, 0, 0, 0, n)

	N,C=map(int,input().split())
	for i in range(N):
		s,t,c=map(int,input().split())
		add(s, t, 2**(c-1), 0, 0, n)

	res=0
	for i in range(1,int(1e5)):
		prev=sum(i - 1, i, 0, 0, n)
		curr=sum(i, i+1, 0, 0, n)
		if prev == curr:
			res = max(res, popcount(curr))
		else:
			res = max(res, popcount(curr | prev))

	print(res)

if __name__ == '__main__':
	main()

Submission status: Time Limit Exceeded

Solution code:
tmp = input().rstrip().split()
N = int(tmp[0])
C = int(tmp[1])
dict = {}

min = 100000
max = 0

for  i in range(N):
    work = input().rstrip().split()
    if min > int(work[0]):
        min = int(work[0])
    if max < int(work[1]):
        max = int(work[1])
    if str(work[2]) in dict:
        dict[str(work[2])].append([int(work[0])-0.5,int(work[1])])
    else:
        dict[str(work[2])] = [[int(work[0])-0.5,int(work[1])]]

def myrange(x,work):
    for loop in range(len(work)):
        if work[loop][0] <= x and work[loop][1] >= x:
            return True
    return False

result = 0

for time in range(min,max+1):
    count = 0
    for k in range(C+1):
        if str(k) in dict:
            if myrange(time,dict[str(k)]):
                count +=1
    if count > result:
        result = count
print(result)

Submission status: Time Limit Exceeded

Solution code:
N, C = map(int, input().split())
S = []
for i in range(N):
    S.append(list(map(int, input().split())))
S.sort()
R = [[] for i in range(C)]
for i in range(N):
    c = S[i][2] - 1
    if R[c]:
        if R[c][-1][1] == S[i][0]:
            R[c][-1][1] = S[i][1]
            continue
    R[c].append(S[i][:])
    R[c][-1][0] -= 0.5
maxDup = 0
for r in R:
    for s in r:
        dup1 = 1
        dup2 = 1
        for rr in R:
            if rr == r:
                continue
            for ss in rr:
                if (s[0] >= ss[0] and s[0] < ss[1]):
                    dup1 += 1
                if (s[1] >= ss[0] and s[1] <= ss[1]):
                    dup2 += 1
        if maxDup < max(dup1, dup2):
            maxDup = max(dup1, dup2)
print(maxDup)

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
INF = float("inf")
sys.setrecursionlimit(10**7)

# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W


def main():
    N, C = list(map(int, input().split()))
    a = []
    check_set = set()
    for _ in range(N):
        s, t, c = list(map(int, input().split()))
        a.append((s - 0.5, s, t, c))
        check_set.add((s - 0.5, c))
        check_set.add((s, c))
        check_set.add((t - 0.01, c))

    ans = 0
    for t1, c1 in check_set:
        total = 0
        for sp2, s2, t2, c2 in a:
            if c1 == c2:
                total += s2 <= t1 <= t2
            else:
                total += sp2 <= t1 <= t2
        ans = max(ans, total)
    print(ans)

    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import collections
N,C=map(int,raw_input().split())
#print N,C
d = collections.defaultdict(list)
start=float("inf")
end=0
for i in range(N):
	s,t,c=map(int,raw_input().split())
	d[c].append((s,t))
	start=min(start,s)
	end=max(end,t)

#print start,end
#print d
[d[i].sort() for i in d.keys()]
#print d

c = collections.defaultdict(list)

for i in range(start,end):
	#print "# i"
	#print i
	cnt=0
	for j in d:
		for k in d[j]:
			if i>=k[0] and i<=k[1]:
				#print j,"Yes"
				c[i].append(j)
				break;

#print c

max_recs=0
for i in c.values():
	max_recs=max(max_recs,len(i))

print max_recs

Submission status: Time Limit Exceeded

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

N, C = list(map(int,input().split()))
MAXTIME = 2*10**5+5
channel = [[0 for i in range(MAXTIME)] for j in range(C)]
arr = [0 for i in range(MAXTIME)]
for i in range(N):
    s,t,c = list(map(int,input().split()))
    channel[c-1][2*s-1] = 1
    channel[c-1][2*t] = -1
for i in range(MAXTIME-1):
    for j in range(C):
        if(channel[j][i]==1 and channel[j][i+1]==-1):
            pass
        else:
            arr[i] += channel[j][i]

ans = 0
use = 0
for i in range(MAXTIME):
    use += arr[i]
    ans = max(ans,use)
print(ans)

Submission status: Time Limit Exceeded

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

N, C = list(map(int,input().split()))
MAXTIME = 2*10**5+5
channel = [[0 for i in range(MAXTIME)] for j in range(C)]
arr = [0 for i in range(MAXTIME)]
for i in range(N):
    s,t,c = list(map(int,input().split()))
    channel[c-1][2*s-1] = 1
    channel[c-1][2*t] = -1
for i in range(MAXTIME-1):
    for j in range(C):
        if(not (channel[j][i]==1 and channel[j][i+1]==-1)):
            arr[i] += channel[j][i]

ans = 0
use = 0
for i in range(MAXTIME):
    use += arr[i]
    ans = max(ans,use)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
N, C = map(int, input().split())
table = [[0] * C for i in range(2 * 10 ** 5 + 2)]
for i in range(N):
    s, t, c = map(int, input().split())
    table[2 * s - 1][c - 1] = 1
    table[2 * t][c - 1] = -1

ans = [0] * (2 * 10 ** 5 + 2)
for i in range(1, 2 * 10 ** 5 + 2):
    for j in range(C):
        if table[i - 1][j] == 1 and table[i][j] == 0:
            table[i][j] = 1
    ans[i] = sum(map(lambda x: abs(x), table[i]))

print(max(ans[1:]))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
N, C = map(int, input().split())
table = [[0] * C for i in range(2 * 10 ** 5 + 1)]
for i in range(N):
    s, t, c = map(int, input().split())
    table[2 * s][c - 1] = 1
    table[2 * t][c - 1] = -1

ans = 0
for i in range(1, 2 * 10 ** 5 + 1):
    for j in range(C):
        if table[i - 1][j] == 1 and table[i][j] == 0:
            table[i][j] = 1
    ans = max(ans, sum(map(lambda x: abs(x), table[i])))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N, C = map(int, input().split(' '))
s = []
t = []
c = []
for i in range(N):
    s_i, t_i, c_i = map(int, input().split(' '))
    s.append(s_i)
    t.append(t_i)
    c.append(c_i - 1)
T = 2*max(t)
table = np.zeros(T)
for i in range(C):
    table_i = np.zeros(T)
    for j in range(N):
        if c[j] == i:
            table_i[2*s[j]-1: 2*t[j]] += 1
    table += list(map(lambda x: 1 if x>0 else 0, table_i))
print(int(np.max(table)))

Submission status: Time Limit Exceeded

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

ss = [0] * N
tt = [0] * N
cc = [0] * N

for n in range(N):
    ss[n], tt[n], cc[n] = map(int, input().split(' '))

L = 10 ** 5 * 2 + 2
timeline = [[0] * L for c in range(C)]

# print(len(timeline), len(timeline[0]))

# 同じチャンネルでマージ
for n in range(N):
    timeline[cc[n] - 1][ss[n] * 2] += 1
    timeline[cc[n] - 1][tt[n] * 2] -= 1

# チャンネルのスタート時間0.5ずらして一個前のところに
num = [0] * L
for c in range(C):
    for t in range(L):
        if timeline[c][t] > 0:
            num[t - 1] += timeline[c][t]
        if timeline[c][t] < 0:
            num[t] += timeline[c][t]

stack = 0
max_ = 0
for i in range(L):
    stack += num[i]
    if stack > max_:
        max_ = stack

print(max_)
# 3 2
# 1 3 1
# 3 4 1
# 4 5 2

Submission status: Time Limit Exceeded

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

ss = [0] * N
tt = [0] * N
cc = [0] * N

for n in range(N):
    ss[n], tt[n], cc[n] = map(int, input().split(' '))

L = 10 ** 5 * 2 + 2
timeline = [[0] * L for c in range(C)]

# print(len(timeline), len(timeline[0]))

# 同じチャンネルでマージ
for n in range(N):
    timeline[cc[n] - 1][ss[n] * 2] += 1
    timeline[cc[n] - 1][tt[n] * 2] -= 1

# チャンネルのスタート時間0.5ずらして一個前のところに
for c in range(C):
    for t in range(L):
        if timeline[c][t] > 0:
            timeline[c][t - 1] = timeline[c][t]
            timeline[c][t] = 0

max_ = 0
stack = 0
for t in range(L):
    for c in range(C):
        stack += timeline[c][t]
    if stack > max_:
        max_ = stack

print(max_)

# 3 2
# 1 3 1
# 3 4 1
# 4 5 2

Submission status: Time Limit Exceeded

Solution code:
import sys

line = sys.stdin.readline()
N, C = [int(x) for x in line.strip().split()]

STC = []

for i in range(N):
    line = sys.stdin.readline().strip()
    xs = [int(x) for x in line.split()] + [0]
    STC.append(xs)

STC.sort(key=(lambda x:(x[0],x[1])))

r = 0
n = 0
while n < N:
    t = 0
    c = 0
    i = 0
    while i < len(STC):
        x = STC[i]
        if x[3] == 1:
            i += 1
            continue
        xt = x[0]
        if x[2] != c:
            xt -= 0.5
        if t <= xt:
            t = x[1]
            c = x[2]
            x[3] = 1
            n += 1
        i += 1
    r += 1

print(r)

Submission status: Time Limit Exceeded

Solution code:
import sys

line = sys.stdin.readline()
N, C = [int(x) for x in line.strip().split()]

STC = []

for i in range(N):
    line = sys.stdin.readline().strip()
    xs = [int(x) for x in line.split()] + [0]
    STC.append(xs)

STC.sort(key=(lambda x:(x[0],x[1])))

r = 0
n = 0
while n < N:
    t = 0
    c = 0
    i = 0
    while i < len(STC):
        x = STC[i]
        if x[3] == 1:
            i += 1
            continue
        xt = x[0]
        if x[2] != c:
            xt -= 0.5
        if t <= xt:
            j = i
            while j < len(STC):
                if STC[j][0] == x[0] and x[2] == c:
                    i = j
                    x = STC[i]
                    break
                if STC[j][0] > x[0]:
                    break
                j += 1
            # print(r, t, c, x)
            t = x[1]
            c = x[2]
            x[3] = 1
            n += 1
        i += 1
    r += 1

print(r)

Submission status: Time Limit Exceeded

Solution code:
N_C = list(map(int, input().split()))
s_t_c = []
for i in range(N_C[0]):
    s_t_c.append(list(map(int, input().split())))

max_number = 0
for j in range(10 ** 5):
    number = 0
    for k in range(N_C[0]):
        if s_t_c[k][0] <= j - 1 and s_t_c[k][1] >= j:
            number = number + 1
        if s_t_c[k][0] <= j and s_t_c[k][1] >= j + 1:
            number = number + 1
        if s_t_c[k][0] <= j - 1 and s_t_c[k][1] >= j + 1:
            number = number - 1
    max_number = max(max_number, number)

print(max_number)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N, C = map(int, input().split(' '))
s = []
t = []
for i in range(N):
    s_i, t_i, c_i = map(int, input().split(' '))
    s.append(s_i)
    t.append(t_i)
T = max(t)
table = np.zeros(2*T)
schedule = np.zeros(2*T)
for i in range(N):
    schedule[:] = 0
    schedule[2*s[i]-1: 2*t[i]] = 1
    table += schedule
print(int(np.max(table)))