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

Solution code:
N, C = map(int, input().split())
timeTable = [tuple(map(int, input().split())) for i in range(N)]
sutyoku =  [[] for i in range(20003)]

for s,t,c in timeTable:
    if s == 0:
        for i in range(2*t):
            sutyoku[i].append(c)
    else:
        for i in range(2*s-1,2*t):
            sutyoku[i].append(c)

su_len = []
for s in sutyoku:
    su_len.append(len(set(s)))

print(max(su_len))

Submission status: Runtime Error

Solution code:
N, C = map(int, input().split())
timeTable = [tuple(map(int, input().split())) for i in range(N)]
sutyoku =  [{0} for i in range(20003)]

for s,t,c in timeTable:
    if s == 0:
        for i in range(2*t):
            sutyoku[i].add(c)
    else:
        for i in range(2*s-1,2*t):
            sutyoku[i].add(c)

ans = 0
for s in sutyoku:
    ans = max(ans, len(s)-1)

print(ans)

Submission status: Runtime Error

Solution code:
N, C = map(int, input().split())
timeTable = [tuple(map(int, input().split())) for i in range(N)]
sutyoku =  [set() for i in range(20002)]

for s,t,c in timeTable:
    if s == 0:
        for i in range(2*t):
            sutyoku[i].add(c)
    else:
        for i in range(2*s-1,2*t):
            sutyoku[i].add(c)

ans = 0
for s in sutyoku:
    ans = max(ans, len(s))

print(ans)

Submission status: Runtime Error

Solution code:
N, C = map(int, input().split())
timeTable = [tuple(map(int, input().split())) for i in range(N)]
sutyoku =  [set() for i in range(20003)]

for s,t,c in timeTable:
    if s == 0:
        for i in range(2*t):
            sutyoku[i].add(c)
    else:
        for i in range(2*s-1,2*t):
            sutyoku[i].add(c)

ans = 0
for s in sutyoku:
    ans = max(ans, len(s))

print(ans)

Submission status: Runtime Error

Solution code:
N, C = map(int, input().split())
s_list = []
t_list = []
c_list = []
for i in range(N):
    s_i, t_i, c_i = map(int, input().split())
    s_list.append(s_i)
    t_list.append(t_i)
    c_list.append(c_i)


time = [0 for i in range(max(t_list))]

for i in range(N):
    rg = t_list[i]-s_list[i]
    for ii in range(N):
        time[s_list[i]+ii-1] += 1

print(max(time))

Submission status: Runtime Error

Solution code:
N, C = map(int, input().split())
s_list = []
t_list = []
c_list = []
for i in range(N):
    s_i, t_i, c_i = map(int, input().split())
    s_list.append(s_i)
    t_list.append(t_i)
    c_list.append(c_i)


time = [0 for i in range(max(t_list))]

for i in range(N):
    rg = t_list[i]-s_list[i]
    for ii in range(N):
        time[s_list[i]+ii] += 1

print(max(time))

Submission status: Runtime Error

Solution code:
def func():
    tvs = []
    for i in range(num):
        tvs.append((-1, -1))
    for i in range(len(bans)):
        now = bans[i][0]
        can = bans[i][1]
        for j, tv in enumerate([tv for tv in tvs if tv[1] == can] + [tv for tv in tvs if tv[1 != can]]):
            if tv[1] == -1 or (tv[1] == can and tv[0] <= now) or tv[0] <= now - 1:
                del tvs[j]
                tvs.append((bans[i][1], can))
                break
        else:
            return False
    return True


n, C = map(int, input().split())

bans = []
for i in range(n):
    s, t, c = map(int, input().split())
    bans.append((2 * s, 2 * t, c))
bans.sort(key=lambda x: x[0])

for num in range(1, 1024):
    if func():
        print(num)
        break

Submission status: Runtime Error

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

# arr[col] には、区間の始まり ==> 1,区間中 ==> 0,区間終わり ==> -1
# 連続した区間は結合した形で表現される

arr = [[0]*L for j in range(c)]
for i in range(n):
    s,t,col = map(int,input().split(" "))
    arr[col][s] += 1
    arr[col][t] -= 1

imos = [0]*L

#全チャンネルを同時に考えたいもす法
for i in range(c):
    for p in range(L):
        if arr[i][p] == 1: imos[p] += 1    
        if arr[i][p] == -1: imos[p+1] -= 1


#累積和をとれば、区間内の最大のrec数は値のmax.
ans = 0
for i in range(1,L):
    imos[i] += imos[i-1]
    ans = max(ans, imos[i])

print(ans)

Submission status: Runtime Error

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

# arr[col] には、区間の始まり ==> 1,区間中 ==> 0,区間終わり ==> -1
# 連続した区間は結合した形で表現される

arr = [[0]*L for j in range(c)]
for i in range(n):
    s,t,col = map(int,input().split(" "))
    arr[col][s] += 1
    arr[col][t] -= 1

imos = [0]*L

#全チャンネルを同時に考えたいもす法
for i in range(c):
    for p in range(L):
        if arr[i][p] == 1: imos[p] += 1    
        if arr[i][p] == -1: imos[p+1] -= 1


#累積和をとれば、区間内の最大のrec数は値のmax.
ans = 0
for i in range(1,L):
    imos[i] += imos[i-1]
    ans = max(ans, imos[i])

print(ans)

Submission status: Runtime Error

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

# arr[col] には、区間の始まり ==> 1,区間中 ==> 0,区間終わり ==> -1
# 連続した区間は結合した形で表現される
arr = [[0]*L for j in range(c)]
for _ in range(n):
    s,t,col = map(lambda x:int(x)-1, input().split())
    arr[col][s] += 1
    arr[col][t] -= 1

imos = [0]*L

#全チャンネルを同時に考えたいもす法
for i in range(c):
    for p in range(L):
        if arr[i][p] == 1: imos[p] += 1    
        if arr[i][p] == -1: imos[p+1] -= 1


#累積和をとれば、区間内の最大のrec数は値のmax.
ans = 0
for i in range(1,L):
    imos[i] += imos[i-1]
    ans = max(ans, imos[i])

print(ans)

Submission status: Runtime Error

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

ans = 0
for i in range(1, 10 ** 5 + 1):
    table[i] += table[i - 1]
    ans = max(ans, table[i])

print(ans)

Submission status: Runtime Error

Solution code:
n,c = map(int, input().split())
queue = [[] for _ in range(c)]
for _ in range(n):
    s,t,c = map(int, input().split())
    if s*2 in queue[c-1]:
        i = queue[c-1].index(s*2)
        queue[c-1][i] = t*2
    elif t*2-1 in queue[c-1]:
        i = queue[c-1].index(t*2-1)
        queue[c-1][i] = s*2-1
    else:
        queue[c-1].extend([s*2-1,t*2])

remove = []
for channel in range(c):
    if queue[channel]:
        queue[channel].sort(reverse=True) #1
    else:
        remove.append(channel)
else:
    while remove:
        channel = remove.pop()
        del queue[channel]
    else:
        queue.sort(key=lambda x: x[0], reverse=True) #2

c = len(queue)
max_rec = 0
now_rec = [False for _ in range(c)]
for time in range(1,200001):
    for channel in range(c):
        if time == queue[channel][-1]:
            queue[channel].pop() #1
            now_rec[channel] = not now_rec[channel]
    else:
        max_rec = max(sum(now_rec), max_rec)
        while queue[-1] == []:
            queue.pop() #2
            c -= 1

else:
    print(max_rec)

Submission status: Runtime Error

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


ans = 0
for i in range(1, 10 ** 5):
    for j in range(C):
        table[i][j] += table[i - 1][j]
    ans = max(ans, sum(table[i]))

print(ans)

Submission status: Runtime Error

Solution code:
n,c = map(int, input().split())
request = [[] for _ in range(c)]
for _ in range(n):
    s,t,c = map(int, input().split())
    if s in request[c-1]:
        i = request[c-1].index(s)
        request[c-1][i] = t
    elif t in request[c-1]:
        i = request[c-1].index(t)
        request[c-1][i] = s
    else:
        request[c-1].extend([s,t])

queue = []
for i in range(c):
    while request[i]:
        t = request[i].pop()
        s = request[i].pop()
        s -= 0.5
        l = t-s
        queue.extend([s,t])
queue.sort(key=lambda x: x[1], reverse)

rec = 0
while queue:
    rec += 1
    x = queue.pop()
    t = x[1]
    l = len(queue)-1
    for i in range(l,-1,-1):
        if queue[i][0] > t:
            x = queue.pop(i)
            t = x[1]
        else:
            continue
else:
    print(rec)

Submission status: Runtime Error

Solution code:
#include <iostream>
using namespace std;

int tasu = 2;
int main(){
    int rec[30][1000000] = {0};
    int n, c;
    cin >> n >> c;
    int s[100000] = {0};
    int t[100000] = {0};
    int ch[100000] = {0};
    for(int i = 0; i < n ; i++) cin >> s[i] >> t[i] >> ch[i];

    for(int i = 0; i < tasu ; i++){
        for(int j = 0; j < n; j++){
            if(rec[s[j]] == 0 && rec[t[j]] == 0){
                for(int k = s[j]; k < t[j] - s[j]; k++) rec[i][j] = 1;}
                else tasu += 1;
            }
        }

        cout << tasu-1 << endl;
    return 0;
}

Submission status: Runtime Error

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

table=[0]*10**5
end=[[] for i in range(10**5)]
for _ in range(N):
  s,t,c=map(int,raw_input().split(' '))
  end[t].append(c)
  i=s
  if not (c in end[i] or end[i]==[]) and i!=0:
    table[i-1]+=1
  table[i]+=1
  i+=1
  while i<t:
    table[i]+=1
    i+=1

print max(table)

Submission status: Runtime Error

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

table=[0]*10**5
end=[[] for i in range(10**5)]
for _ in range(N):
  s,t,c=map(int,raw_input().split(' '))
  end[t].append(c)
  i=s
  if not (c in end[i] or end[i]==[]):
    table[i-1]+=1
  table[i]+=1
  i+=1
  while i<t:
    table[i]+=1
    i+=1

print max(table)

Submission status: Runtime Error

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

N, C = list(map(int,input().split()))
channel = [[0 for i in range(2*N+7)] for j in range(C)]
arr = [0 for i in range(2*N+7)]
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(2*N+6):
    for j in range(C):
        if(channel[j][i]==1 and channel[j][i+1]==-1):
            channel[j][i] = 0
            channel[j][i+1] = 0

ans = 0
use = 0
for i in range(2*N+7):
    for j in range(C):
        use += channel[j][i]
        ans = max(ans,use)
print(ans)

Submission status: Runtime Error

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

import numpy as np

nc = raw_input()
nc = nc.split()
n,c = map(int,nc)

tt = np.zeros([(10**2),c],int)

for i in range(n):
    stc = raw_input()
    stc = stc.split()
    s,t,c = map(int,stc)
    j = s
    while j <= t:
        tt[j-1][c-1] = 1
        j += 1

ans = np.max(np.sum(tt, axis=1))

print ans

Submission status: Runtime Error

Solution code:
n, c_no = list(map(int, input().split()))
s, t = [], []
c = []
for i in range(c_no):
    c.append([])
for i in range(n):
    stc = list(map(int, input().split()))
    c[stc[2] - 1].append([stc[0], stc[1]])
a = 10**5*[0]
for i in range(len(c)):
    tmp = 10**5*[0]
    c[i].sort()
    for j in range(len(c[i])):
        for k in range(c[i][j][1] - c[i][j][0] + 1):
            if(tmp[c[i][j][0] + j - 1] == 0):
                tmp[c[i][j][0] + j - 1] += 1
    for j in range(10**5):
        a[j] += tmp[j]
print(max(a))

Submission status: Runtime Error

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(' '))

timeline = [0] * (10 ** 5)

for n in range(N):
    timeline[ss[n] - 1] += 1
    timeline[tt[n]] -= 1

max_ = 0
stack = 0
for t in timeline:
    stack += t
    if stack > max_:
        max_ = stack
        
print(max_)

Submission status: Runtime Error

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

def solve():
    n, c = map(int, input().split())
    c_info = [[int(i) for i in input().split()] for _ in range(n)]
    c_info.sort(key=lambda x: (x[2], x[0]))
    info = []
    cnt = 0
    while cnt < n:
        if cnt == n - 1:
            info.append(c_info[cnt])
            break
        if c_info[cnt][1] == c_info[cnt + 1][0] and c_info[cnt][2] == c_info[cnt + 1][2]:
            tc = c_info[cnt][2]
            t = [c_info[cnt][0], c_info[cnt + 1][1], tc]
            cnt += 1
            while cnt < n - 1 and t[1] == c_info[cnt + 1][0] and tc == c_info[cnt + 1][2]:
                t = [t[1], c_info[cnt + 1][1], tc]
                cnt += 1
            info.append(t)
            if cnt == n - 1:
                break
        else:
            info.append(c_info[cnt])
        cnt += 1

    tarr = [0] * (1 + 10 ** 5)
    for elem in info:
       tarr[elem[0]] += 1
       tarr[elem[1] + 1] -= 1
    
    ans = 1
    tans = 0
    for elem in tarr:
        tans += elem
        ans = max(ans, tans)
    print(ans)

if __name__=="__main__":
    solve()

Submission status: Runtime Error

Solution code:
from heapq import heappop as pop, heappush as push

peak, curr = 0, 0

stuff = []
n, c = map(int, raw_input().split())
for _ in xrange(n):
  stuff.append(map(float, raw_input().split()))
  
stuff = sorted(stuff)
has_camera = [False] * c
ending = []
for st, end, ch in stuff:
  while ending[0][0] <= st - 0.5:
    _, cch = pop(ending)
    has_camera[cch] = False
    curr -= 1
  if not has_camera[ch]:
    curr += 1
  push(ending, (end, ch))
  peak = max(peak, curr)
  
 print peak

Submission status: Runtime Error

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

su = [0]*(10**5+1)
Q = [[] for i in range(C)]
for i in range(N):
    s, t, c = map(int, input().split())
    Q[c-1].append([s, t])
R = [[] for i in range(C)]
for i in range(C):
    q = Q[i]; q.sort()
    r = R[i]
    r.append(q[0])
    for j in range(1, len(q)):
        if r[-1][1] == q[j][0]:
            r[-1][1] = q[j][1]
        else:
            r.append(q[j])
    for a, b in r:
        su[a-1] += 1
        su[b] -= 1
ans = 0; tmp = 0
for i in range(10**5+1):
    tmp += su[i]
    ans = max(ans, tmp)
print(ans)

Submission status: Runtime Error

Solution code:
n,c = map(int,input().split())
table = [0 for i in range(100000)]
count = 0
while(count < n):
    count += 1
    s,t,c2 = map(int,input().split())
    cou2 = s
    while(cou2 <= t):
        table[cou2] = table[cou2]+ 1
        cou2 += 1

print(max(table))

Submission status: Runtime Error

Solution code:
import numpy as np
n,c = map(int,input().split())
table = list(np.zeros(100000,dtype="int"))
count = 0
while(count < n):
    count += 1
    s,t,c2 = map(int,input().split())
    cou2 = s
    while(cou2 <= t):
        table[cou2] = table[cou2]+ 1
        cou2 += 1

print(max(table))

Submission status: Runtime Error

Solution code:
import numpy as np
n,c = map(int,input().split())
table = list(np.zeros(100000,dtype="int"))
count = 0
while(count < c):
    count += 1
    s,t,c = map(int,input().split())
    cou2 = s
    while(cou2 <= t):
        table[cou2] = table[cou2]+ 1
        cou2 += 1

print(max(table))