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

Solution code:
def recording(N: int, C: int, info: list) -> int:
    _, max_time, _ = max(info, key=lambda x: x[1])
    max_time = 2*max_time

    # 各チャンネルでのレコーダーの使用数を累積和として求める。
    # recorders が累積和であり、S-0.5 を配列で表すために
    # 2*(max_time) のサイズにしている。
    recorders = [[0] * C for _ in range(max_time + 1)]

    # スタート時間を +1 、終了時間を -1 とすることで、あとで
    # 累積和をとるときに、録画している時間帯が 1 、していない
    # 時間が 0 になるようにできる。
    for s, t, ch in info:
        recorders[2*s-1][ch-1] += 1
        recorders[2*t][ch-1] -= 1

    # 累積和をとる。
    for t in range(max_time):
        for ch in range(C):
            recorders[t+1][ch] += recorders[t][ch]

    # 各時間帯でのレコーダーの使用台数の最大値をとる。
    return max(
        sum(used > 0 for used in recorders[t])
        for t in range(max_time+1))


if __name__ == "__main__":
    N = 0
    N, C = map(int, input().split())
    info = [tuple(map(int, input().split())) for _ in range(N)]
    ans = recording(N, C, info)
    print(ans)

Submission status: Accepted

Solution code:
def recording(N: int, C: int, info: list) -> int:
    _, max_time, _ = max(info, key=lambda x: x[1])
    max_time = 2*max_time

    # 各チャンネルでのレコーダーの使用数を累積和として求める。
    # cum が累積和であり、S-0.5 を配列で表すために 2*(10**5)
    # のサイズにしている。
    cum = [[0] * C for _ in range(max_time + 1)]

    # スタート時間を +1 、終了時間を -1 とすることで、あとで
    # 累積和をとるときに、録画している時間帯が 1 、していない
    # 時間が 0 になるようにできる。
    for s, t, ch in info:
        cum[2*s-1][ch-1] += 1
        cum[2*t][ch-1] -= 1

    # 累積和をとる。
    for t in range(max_time):
        for ch in range(C):
            cum[t+1][ch] += cum[t][ch]

    # 各時間帯でのレコーダーの使用台数の最大値をとる。
    return max(sum(used > 0 for used in cum[t]) for t in range(max_time+1))


if __name__ == "__main__":
    N = 0
    N, C = map(int, input().split())
    info = [tuple(map(int, input().split())) for _ in range(N)]
    ans = recording(N, C, info)
    print(ans)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import itertools
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return list(sys.stdin.readline())
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
mod = 1000000007

#C
def C():
    N = I()
    F = LIR(N)
    P = LIR(N)
    ans = -1*float("INF")
    kaiten = list((itertools.product([0,1], repeat=10)))
    del kaiten[0]
    for patern in kaiten:
        i = list(patern)
        anskaiten = [0 for i in range(N)]
        for youbi, n in enumerate(i):
            if n == 1:
                for nn,f in enumerate(F):
                    if f[youbi] == 1:
                        anskaiten[nn] += 1
        ansb = 0
        #print(anskaiten, end="")
        for k, p in enumerate(P):
            ansb += p[anskaiten[k]]
        ans = max(ans, ansb)
    print(ans)
        
def D():

    N, C = LI()
    STC = LIR(N)
    ans = 0
    
    #テレビチャンネルのテーブルを作成
    channel = [[0]*(10**5+2) for i in range(C+1)]

    #IMOS法を使用
    
    #初めにチャンネルテーブルごとの録画する時間の初めに+1
    #終わりの時間+1に-1をする
    #これは他チャンネルに変える際終わる時間と始まる時間が
    #同じとき録画機が2個いることを加味して+1ずらしている
    for s,t,c in STC:
        channel[c][s] += 1
        channel[c][t + 1] -= 1
    
    #次にチャンネルテーブルすべてを更新し、録画番組が
    #流れていないチャンネルには0をあたえ、そうでないときは
    #0以外の数字を与える
    for cha in channel:
        for num, CH in enumerate(cha):
            if num == 10 ** 5 + 1:
                break
            cha[num + 1] += CH
    
    #最後に毎秒ごとにチャンネルテーブルを見て番組が流れている
    #時はその時間の録画機を1追加し、秒数ごとに分け最大値を出力
    for i in range(10 ** 5 + 1):
        bf = 0
        for cha in channel:
            if cha[i]: bf += 1
        ans = max(ans, bf)
    print(ans)

if __name__ == '__main__':
    D()

Submission status: Accepted

Solution code:
import sys

def main():
    input = sys.stdin.readline
    N, C = map(int, input().split())
    dic = [[] for _ in range(C + 1)]
    for _ in range(N):
        s, t, c = input().split()
        dic[int(c)].append([int(s), int(t)])
    for c in range(C + 1):
        l = len(dic[c])
        if l == 1:
            continue
        dic[c] = sorted(dic[c])
        i = 0
        while i < l - 1:
            if i < l - 1 and dic[c][i][1] == dic[c][i + 1][0]:
                dic[c][i + 1][0] += 1
            else:
                i += 1
    f = [0 for _ in range(100002)]
    for c in range(C + 1):
        for t in dic[c]:
            f[t[0]] += 1
            f[t[1] + 1] -= 1
    ans = 0
    for i in range(1, 100001):
        f[i] += f[i - 1]
        if ans < f[i]:
            ans = f[i]
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    n = I()
    f = LIR(n)
    po = [1]*11
    for i in range(n):
        k = 0
        p = 1
        for j in range(10):
            k += p*f[i][j]
            p *= 2
            po[j+1] = p
        f[i] = k
    p = LIR(n)
    ans = -float("inf")
    for i in range(1,1024):
        k = 0
        for j in range(n):
            c = i&f[j]
            s = 0
            for l in po:
                if c&l:s += 1
            k += p[j][s]
        ans = max(ans,k)
    print(ans)
#D
def D():
    n,C = LI()
    T = [[0 for i in range(100002)] for j in range(C)]
    for i in range(n):
        s,t,c = LI()
        c -= 1
        T[c][s] += 1
        T[c][t+1] -= 1
    for c in range(C):
        for i in range(100000):
            T[c][i+1] += T[c][i]
    ans = 0
    for i in range(100000):
        k = 0
        for c in range(C):
            if T[c][i]:k += 1
        ans = max(ans, k)
    print(ans)
#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    D()

Submission status: Accepted

Solution code:
import sys

def main():
    input = sys.stdin.readline
    N, C = map(int, input().split())
    dic = [[] for _ in range(C + 1)]
    for _ in range(N):
        s, t, c = input().split()
        dic[int(c)].append([int(s), int(t)])
    for c in range(C + 1):
        l = len(dic[c])
        if l == 1:
            continue
        dic[c] = sorted(dic[c])
        i = 0
        while i < l - 1:
            if i < l - 1 and dic[c][i][1] == dic[c][i + 1][0]:
                dic[c][i + 1][0] += 1
            else:
                i += 1
    f = [0 for _ in range(100002)]
    for c in range(C + 1):
        for t in dic[c]:
            f[t[0]] += 1
            f[t[1] + 1] -= 1
    ans = 0
    for i in range(1, 100001):
        f[i] += f[i - 1]
        if ans < f[i]:
            ans = f[i]
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    n,C = LI()
    T = [[0 for i in range(200002)] for j in range(C)]
    for i in range(n):
        s,t,c = LI()
        c -= 1
        T[c][2*s] += 1
        T[c][2*t+1] -= 1
    for c in range(C):
        for i in range(200000):
            T[c][i+1] += T[c][i]
    ans = 0
    for i in range(200000):
        k = 0
        for c in range(C):
            if T[c][i]:k += 1
        ans = max(ans, k)
    print(ans)
#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    D()

Submission status: Accepted

Solution code:
import sys

def main():
    input = sys.stdin.readline
    N, C = map(int, input().split())
    P = [list(map(int, input().split())) for _ in range(N)]
    P = sorted(P, key=lambda x: x[0])

    V = []
    for p in P:
        flag = True
        for i in range(len(V)):
            if V[i][0] < p[0]:
                V[i] = [p[1], p[2]]
                flag = False
                break
            elif V[i][0] == p[0] and V[i][1] == p[2]:
                V[i] = [p[1], p[2]]
                flag = False
                break
            else:
                continue

        if flag:
            V.append([p[1], p[2]])

    print(len(V))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, C = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(N)]
L.sort(key=lambda x: x[0])
R = [(L[0][1], L[0][2])]
for s, t, c in L[1:]:
    for i, (t_r, c_r) in enumerate(R):
        if c == c_r and t_r <= s:
            R[i] = (t, c)
            break
        if c != c_r and t_r < s:
            R[i] = (t, c)
            break
    else:
        R.append((t, c))
print(len(R))

Submission status: Accepted

Solution code:
#080-D
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n,c=IL()
imos=[[0]*30 for i in range(pow(10,5))]
for i in range(n):
    s,t,c=IL()
    for j in range(s-1,t):
        imos[j][c-1]=1
ans=0
for i in range(pow(10,5)):
    ans=max(ans,sum(imos[i]))
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict


def main():
    N, C = list(map(int, input().split(' ')))
    s = []
    t = []
    c = []
    channels = defaultdict(lambda: set())
    for i in range(N):
        si, ti, ci = list(map(int, input().split(' ')))
        for t in range(si-1, ti):
            channels[t].add(ci)
    n_recorders = 0
    for t in channels:
        n_recorders = max(n_recorders, len(channels[t]))
    print(n_recorders)



main()

Submission status: Accepted

Solution code:
START = 0
END = 1


def main():
    N, C = map(int, input().split())
    active = [0] * (C+1)
    seq = []
    for _ in range(N):
        s, t, c = map(int, input().split())
        seq += [(s, START, c), (t, END, c)]
    seq.sort()
    ans = 0
    para = 0
    for i in range(len(seq)):
        time, op, channel = seq[i]
        if op == START:
            if active[channel] == 0:
                para += 1
            active[channel] += 1
        else:
            active[channel] -= 1
            if active[channel] == 0:
                para -= 1
        ans = max(ans, para)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

N,C=rl()
stc = [rl() for _ in range(N)]
stc.sort(key=lambda x:(x[2],x[0]))
nstc = []
for s,t,c in stc:
    if len(nstc) != 0 and nstc[-1][2] == c and nstc[-1][1] == s:
        nstc[-1][1] = t
    else:
        nstc.append([s,t,c])

n = len(nstc)

TT=[0]*(2*10**5+5)
for i in range(n):
    TT[2*nstc[i][0] - 1] += 1
    TT[2*nstc[i][1]] -= 1
for i in range(1,len(TT)):
    TT[i] += TT[i-1]
print(max(TT))

Submission status: Accepted

Solution code:
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

N,C=rl()
st = [[] for _ in range(C)]
TT1 = [0 for _ in range(10**5+2)]
for i in range(N):
    s,t,c = rl()
    TT1[s] += 1
    TT1[t+1] -= 1
    st[c-1].append([s,t])
for st_i in range(len(st)):
    st_ = st[st_i]
    if len(st_) <= 1: continue
    st_.sort(key=lambda x:x[0])
    l = []
    new = 0
    lst_ = len(st_)
    for i in range(lst_):
        if new == 0:
            s,t = st_[i]
            if i != lst_ -1 and t==st_[i+1][0]:
               new = 1
               continue
            else:
                l.append([s,t])
        else:
            t = st_[i][1]
            if i != lst_ -1 and t==st_[i+1][0]:
                new = 1
                continue
            else:
                l.append([s,t])
    st[st_i] = l


TT2 = [0 for _ in range(10**5+2)]

for st_ in st:
    if len(st_) == 0: continue
    for i in range(len(st_)):
        TT2[st_[i][0]] += 1
        TT2[st_[i][1]+1] -= 1

for i in range(1,len(TT1)):
    TT1[i] += TT1[i-1]
    TT2[i] += TT2[i-1]

print(min(max(TT1),max(TT2)))

Submission status: Accepted

Solution code:
import pprint

N, C = map(int, input().split())
stc = []

max_time = 0
for _ in range(N):
    tmp = list(map(int,input().split()))
    max_time = max(max_time,tmp[1])
    stc.append(tmp)

stc.sort(key=lambda x: (x[0]))
# pprint.pprint(stc,width=20)
# print(max_time)

ongoings = []

ans = 0

for prog in stc:
    # print("prog:",prog)
    flag = False
    for og in ongoings:
        if og[2] == prog[2]:
            og[1] = prog[1]
            flag = True
            break
        elif og[1] < prog[0]:
            og[1] = prog[1]
            og[2] = prog[2]
            flag = True
            break
    if not flag:
        ongoings.append(prog)
    # print("ogs:",ongoings)
    ans = max(ans,len(ongoings))

print(ans)

Submission status: Accepted

Solution code:
n, c = map(int, input().split())
program = [tuple(map(int, input().split())) for _ in range(n)]
program.sort()
recorder = [(0, -1)] * c
# greedy
for s, t, co in program:
    done = 0
    for i in range(c):
        #search same channel
        f, cp = recorder[i]
        if (f == s or f == s-1) and co == cp:
            recorder[i] = (t, co)
            done = 1
            break
    if done == 0:
        for i in range(c):
            f, cp = recorder[i]
            if f < s:
                recorder[i] = (t, co)
                break
ret = 0
for i in range(c):
    if recorder[i][0] != 0:
        ret += 1
print(ret)

Submission status: Accepted

Solution code:
N, C = map(int, input().split())
S, T = set(), set()
for _ in range(N):
    s, t, c = map(int, input().split())
    S.add((s, c))
    T.add((t, c))
# delete continuous programs
ST = S & T
S -= ST
T -= ST

S = sorted(S)
T = sorted(T)
ans = 0
cnt = 0
si, ti = 0, 0
while si < len(S):
    if S[si][0] <= T[ti][0]:
        cnt += 1
        ans = max(ans, cnt)
        si += 1
    else:
        cnt -= 1
        ti += 1

print(ans)

Submission status: Accepted

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

A.sort(key = lambda x:x[0])
A.sort(key = lambda x:x[2])

for i in range(n-1) :
    if A[i][2] == A[i+1][2] and A[i+1][0] - A[i][1] <= 1 :
        A[i+1][0] = A[i][0]
        A[i] = [-10, 0, 0]
for i in range(n) :
    A[i][0] -= 1

#A.sort(key = lambda x:x[0])

T = [0 for i in range(10**5+10)]
ans = 0
for i in range(n) :
    if A[i][0] != -11 :
        T[A[i][0]] += 1
        T[A[i][1]] -= 1

for i in range(len(T)-1) :
    T[i+1] += T[i]

print(max(T))

Submission status: Accepted

Solution code:
# D
N,C = map(int, input().split())
st = [[] for _ in range(C)]
for _ in range(N):
    si,ti,ci = map(int, input().split())
    st[ci-1].append((si,ti))
    
T_MAX = int(1e5)
imos = [0]*(T_MAX+1)
for ch in range(C):
    if st[ch]==[]: continue
    st[ch].sort()
    prev_s, prev_t = st[ch][0]
    for si,ti in st[ch][1:]:
        if si!=prev_t:
            imos[prev_s-1] += 1
            imos[prev_t] -= 1
        else:
            imos[prev_s-1] += 1
            imos[prev_t-1] -= 1
        prev_s,prev_t = si,ti
    else:
        imos[prev_s-1] += 1
        imos[prev_t] -= 1
# print(imos)
ans = 1
wa = 0
for imosi in imos:
    wa += imosi
    ans = max(ans, wa)
print(ans)

Submission status: Accepted

Solution code:
N,C=map(int,input().split())
M=10**5+2
dp=[[0]*(M) for i in range(30)]
for i in range(N):
    s,t,c = map(int,input().split())
    c=c-1
    dp[c][s-1]+=1
    dp[c][t]-=1
for c in range(30):
    for i in range(1,M):
        dp[c][i]+=dp[c][i-1]
ans=0
for i in range(M):
    t=0
    for c in range(30):
        if dp[c][i]>0:
            t+=1
    ans=max(t,ans)
#print(dp[0][:15])
#print(dp[1][:15])
print(ans)

Submission status: Accepted

Solution code:
N, C = map(int, input().split())
query = [list(map(int, input().split())) for _ in range(N)]
timeTable = [[False for _ in range(10 ** 5)] for _ in range(C)]
time = [0 for _ in range(10 ** 6)]
for q in query:
    s, t, c = q
    for i in range(s - 1, t):
        timeTable[c - 1][i] = True
for channel in timeTable:
    for i in range(10 ** 5):
        if channel[i]:
            time[2 * i - 1] += 1
            time[2 * i] += 1
print(max(time))

Submission status: Accepted

Solution code:
n,c=map(int,input().split())
r=[[0,0]for _ in range(c)]
for s,t,c in sorted(list(map(int,input().split()))for _ in range(n)):
    for m in r:
        if m[0]<s-0.5or m[1]==c and m[0]<=s:
            m[0],m[1]=t,c
            break
print(len(list(filter(lambda x:x!=[0,0],r))))

Submission status: Accepted

Solution code:
import itertools
N,C = map(int,input().split())
imos = [0]*(10**6)
info = [list(map(int,input().split())) for i in range(N)]
info = sorted(info,key=lambda x:(x[2],x[0]))
note = -1
before_t = -1
for i in range(N):
    s,t,c = info[i]
    s -= 1
    if c == note and s < before_t:
        s = before_t
    imos[s] += 1
    imos[t] -= 1
    note = c
    before_t = t
acc_sum = list(itertools.accumulate(imos))
ans = max(acc_sum)
print(ans)

Submission status: Accepted

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

stc.sort()
counter = 0
array = []

for i in stc:
    s, t, c =  i
    flag = True
    for j in range(len(array)):
        if array[j][0] == s and array[j][2] == c or array[j][0] < s:
            array[j] = [t, s, c]
            flag = False
            array.sort(reverse = True)
            break

    if flag:
        array.append([t, s, c])
        array.sort(reverse = True)
        counter += 1

print(counter)

Submission status: Accepted

Solution code:
def merge(s):
    correct_s = []
    s.sort(key = lambda x:(x[2],x[0]))
    min_max = [s[0][0],s[0][1]]
    for i in range(1,len(s)):
        if s[i][2] == s[i-1][2] and s[i][0] == min_max[1]:
            min_max[1] = s[i][1]   
        else:
            correct_s.append([min_max[0],min_max[1],s[i-1][2]])
            min_max[0],min_max[1] = s[i][0],s[i][1]
    else:
        correct_s.append([min_max[0],min_max[1],s[len(s)-1][2]])

    return correct_s
        
        
    
import heapq
N,C = list(map(int,input().split()))
data = []
av = []
for i in range(N):
    data.append(list(map(int,input().split())))
    


s = merge(data)
s.sort()


for i in range(len(s)):
    if i == 0:
        heapq.heappush(av,s[i][1])
    elif s[i][0] <= av[0]:
        heapq.heappush(av,s[i][1])
    else:
        heapq.heappop(av)
        heapq.heappush(av,s[i][1])

print(len(av))

Submission status: Accepted

Solution code:
# coding:utf-8

import sys
import heapq
# from collections import defaultdict, deque

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

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n, c = LI()
tv = [tuple(LI()) for _ in range(n)]

used = [[0] * (10 ** 5 + 1) for _ in range(c)]
for s, t, channel in tv:
    used[channel - 1][s:t + 1] = [1] * (t - s + 1)

ans = 0
for col in zip(*used):
    ans = max(ans, sum(col))

print(ans)

Submission status: Accepted

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

M = 10**5+1
merge = [[0]*(M+1) for _ in range(31)]
for i in range(N):
    s, t, c = STC[i]
    merge[c][s:t+1] = [1]*(t-s+1)
print(max(map(sum, zip(*merge))))

Submission status: Accepted

Solution code:
from itertools import accumulate
N, C = map(int, input().split())
STC = [list(map(int, input().split())) for _ in range(N)]

M = 10**5+1
merge = [[0]*(M+1) for _ in range(31)]
for i in range(N):
    s, t, c = STC[i]
    #merge[c][s] += 1
    #merge[c][t+1] -= 1
    merge[c][s:t+1] = [1]*(t-s+1)
#for c in range(31):
#    merge[c] = list(map(lambda x: int(bool(x)), accumulate(merge[c])))
print(max(map(sum, zip(*merge))))

#ans = []
#for i in range(M+1):
#    res = 0
#    for j in range(31):
#        res += merge[j][i]
#    ans.append(res)
#print(max(ans))

Submission status: Accepted

Solution code:
from itertools import accumulate
N, C = map(int, input().split())
STC = [list(map(int, input().split())) for _ in range(N)]

M = 10**5+1
merge = [[0]*(M+1) for _ in range(31)]
for i in range(N):
    s, t, c = STC[i]
    merge[c][s] += 1
    merge[c][t+1] -= 1
for c in range(31):
    merge[c] = list(map(lambda x: int(bool(x)), accumulate(merge[c])))

ans = []
for i in range(M+1):
    res = 0
    for j in range(31):
        res += merge[j][i]
    ans.append(res)
print(max(ans))

Submission status: Accepted

Solution code:
def inpl(): return list(map(int, input().split()))

N, C = inpl()
stc = [inpl() for _ in range(N)]
stc.sort()

num = [(-1, -1)]
for s, t, c in stc:
    for i, Tuple in enumerate(num):
        # print(s, t)
        ch = Tuple[0]
        ti = Tuple[1]
        if ch != c and s - 0.5 >= ti:
            num[i] = (c, t)
            break
        elif ch == c and s >= ti:
            num[i] = (c, t)
            break
    else:
        num.append((c, t))
print(len(num))

Submission status: Accepted

Solution code:
N,C = map(int,input().split())
STC = [[] for _ in range(C)]
for i in range(N):
    s,t,c = map(int,input().split())
    STC[c-1].append((s,t))

lenA = 200001
A = [[0]*lenA for _ in range(C)]
for i in range(C):
    for (s,t) in STC[i]:
        A[i][s*2-1:t*2] = [1]*(t*2-s*2+1)

Ans = [0]*lenA
for i in range(C):
    for j in range(lenA):
        if A[i][j] > 0:
            Ans[j] += 1

print(max(Ans))

Submission status: Accepted

Solution code:
def show(imos):
    print(imos[:20])
    print()
n, C = [int(i) for i in input().split()]
imos = [[0 for _ in range(C)] for _ in range(10**5+10)]
for i in range(n):
    s, t, c = [int(i) - 1 for i in input().split()]
    imos[s][c] += 1
    imos[t][c] -= 1
# show(imos)
_max = 0
for i in range(1, len(imos)):
    _count = 0
    for j in range(C):
        if imos[i][j] < 0:
            _count += -imos[i][j]
        imos[i][j] += imos[i-1][j]
    _max = max(_max, sum(imos[i]) + _count)
# show(imos)
print(_max)

Submission status: Accepted

Solution code:
N, C = [int(_) for _ in input().split()]
STC = [[int(_) for _ in input().split()] for _ in range(N)]
ST = [[set(), set()] for _ in range(C)]
for s, t, c in STC:
    c -= 1  #0-indexed
    ST[c][0].add(s)
    ST[c][1].add(t)
    if t in ST[c][0]:
        ST[c][0].discard(t)
        ST[c][1].discard(t)
    if s in ST[c][1]:
        ST[c][0].discard(s)
        ST[c][1].discard(s)
D = {}
for i in range(C):
    for s in ST[i][0]:
        D[s - 0.5] = D.get(s - 0.5, 0) + 1
    for t in ST[i][1]:
        D[t] = D.get(t, 0) - 1
times = sorted(D.keys())
count = 0
ans = 0
for time in times:
    count += D[time]
    ans = max(ans, count)
print(ans)

Submission status: Accepted

Solution code:
from itertools import accumulate
N, C = map(int, input().split())
V = [[0] * (10 ** 5 + 1) for i in range(C)]

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

for c in range(C):
    V[c] = list(accumulate(V[c]))

ans = 0
for i in range(10 ** 5 + 1):
    tmp = 0
    for c in range(C):
        tmp += min(1, V[c][i])
    ans = max(ans, tmp)

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

import sys
import math
import fractions
import heapq
import collections
import re
import array
import bisect

from collections import Counter, defaultdict


def array2d(dim1, dim2, init=None):
    return [[init for _ in range(dim2)] for _ in range(dim1)]

II = lambda: int(input())
MI = lambda: map(int, input().split())
DBGLOG = lambda s: sys.stderr.write(s + "\n")


def main():
    N, C = MI()
    STs_tmp = [[] for _ in range(C)]

    for i in range(N):
        s, t, c = MI()
        heapq.heappush(STs_tmp[c-1], (s, t))

    s_cnt = defaultdict(int)
    t_cnt = defaultdict(int)
    times = set()
    for c in range(C):
        ls, lt = None, None
        while STs_tmp[c]:
            s, t = heapq.heappop(STs_tmp[c])
            if ls is None:
                ls, lt = s, t
                continue
            if lt == s:
                lt = t
                continue
            else:
                s_cnt[ls-0.5] += 1
                times.add(ls-0.5)
                t_cnt[lt] += 1
                times.add(lt)
                # DBGLOG("c{} {} - {}".format(c + 1, ls, lt))
                ls, lt = s, t
        if ls is not None:
            s_cnt[ls-0.5] += 1
            times.add(ls-0.5)
            t_cnt[lt] += 1
            times.add(lt)
            # DBGLOG("c{} {} - {}".format(c + 1, ls, lt))

    ans, cnt = 0, 0
    for t in sorted(times):
        cnt += s_cnt[t] - t_cnt[t]
        ans = max(ans, cnt)
        # DBGLOG("t={}\t{}".format(t, cnt))
    return ans


if __name__ == "__main__":
    print(main())

Submission status: Accepted

Solution code:
N, C = map(int, input().split())
time = 10**5+1
channel_list = [[0 for _ in range(time)]for _ in range(C)]
count_list = [0 for _ in range(time)]
for i in range(N):
    s, t, c = map(int, input().split())
    channel_list[c-1][s-1] += 1
    channel_list[c-1][t] -= 1

for i in range(C):
    for t in range(1, time):
        channel_list[i][t] += channel_list[i][t-1]
        if channel_list[i][t] >= 1:
            count_list[t] += 1

print(max(count_list))

Submission status: Accepted

Solution code:
N, C = map(int, input().split())
channel_list = [[0 for _ in range(10**5+1)]for _ in range(C)]
count_list = [0 for _ in range(10**5+1)]
for i in range(N):
    s, t, c = map(int, input().split())
    channel_list[c-1][s-1] += 1
    channel_list[c-1][t] -= 1

for i in range(C):
    for t in range(1, 10**5+1):
        channel_list[i][t] += channel_list[i][t-1]
        if channel_list[i][t] >= 1:
            count_list[t] += 1

print(max(count_list))

Submission status: Accepted

Solution code:
N, C = map(int, input().split())
channel_list = [[0 for _ in range(10**5+1)]for _ in range(C)]
count_list = [0 for _ in range(10**5+1)]
for i in range(N):
    s, t, c = map(int, input().split())
    channel_list[c-1][s-1] += 1
    channel_list[c-1][t] -= 1

for i in range(C):
    for t in range(1, 10**5):
        if t == 10 ** 5:
            continue
        channel_list[i][t] += channel_list[i][t-1]
        if channel_list[i][t] >= 1:
            count_list[t] += 1
x = 0
for t in range(1, 10**5+1):
    count = count_list[t]
    if count > x:
        x = count
print(x)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from operator import itemgetter

N,C = map(int, input().split())
T = 0
record = []
for _ in range(N):
    s,t,c = map(int, input().split())
    T = max(T, t)
    record.append((s,t,c))
record.sort(key=itemgetter(2,0,1))

tl = [0]*(T+1)
curr_channel = None
for r in record:
    s,t,c = r
    if curr_channel==c:
        if curr_time==s:
            tl[s] += 1
            tl[t] -= 1
        else:
            tl[s-1] += 1
            tl[t] -= 1
        curr_time = t
    else:
        tl[s-1] += 1
        tl[t] -= 1
        curr_channel = c
        curr_time = t

s = 0
res = 0
for t in tl:
    s += t
    res = max(res, s)
print(res)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from operator import itemgetter

N,C = map(int, input().split())
record = []
for _ in range(N):
    s,t,c = map(int, input().split())
    record.append((s,t,c))
record.sort(key=itemgetter(1,0,2))

def can_record(k):
    slots = [(-1,-1)]*k  # (end_time, channel)

    for r in record:
        idx = -1
        t = -1
        for i in range(k):
            end_time, channel = slots[i]
            if channel==r[2]:
                if end_time<=r[0]:
                    if t<=end_time:
                        t = end_time
                        idx = i
            else:
                if end_time<r[0]:
                    if t<=end_time:
                        t = end_time
                        idx = i
        if idx==-1:
            return False
        else:
            slots[idx] = (r[1],r[2])
    return True

for k in range(1,C+1):
    if can_record(k):
        print(k)
        break