Problem:


Score : 400 points

Problem Statement

There are N islands lining up from west to east, connected by N-1 bridges.

The i-th bridge connects the i-th island from the west and the (i+1)-th island from the west.

One day, disputes took place between some islands, and there were M requests from the inhabitants of the islands:

Request i: A dispute took place between the a_i-th island from the west and the b_i-th island from the west. Please make traveling between these islands with bridges impossible.

You decided to remove some bridges to meet all these M requests.

Find the minimum number of bridges that must be removed.

Constraints

All values in input are integers.

2 \leq N \leq 10^5

1 \leq M \leq 10^5

1 \leq a_i < b_i \leq N

All pairs (a_i, b_i) are distinct.

Input

Input is given from Standard Input in the following format:

N M
a_1 b_1
a_2 b_2
:
a_M b_M

Output

Print the minimum number of bridges that must be removed.

Sample Input 1

5 2
1 4
2 5

Sample Output 1

1

The requests can be met by removing the bridge connecting the second and third islands from the west.

Sample Input 2

9 5
1 8
2 7
3 5
4 6
7 9

Sample Output 2

2

Sample Input 3

5 10
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
4 5

Sample Output 3

4



Sample input:
5 2
1 4
2 5


Sample output:
1

Submission status: Runtime Error

Solution code:
def main():
    in1 = input()
    n, m = [int(c) for c in in1]

    arr = []
    for i in range(m):
        _in = input()
        a, b = [int(c) for c in _in]
        arr.append((a, b))

    sorted_arr = sorted(arr, key=lambda x: x[0])

    n = 0

    mi, ma = sorted_arr[0]
    for a, b in sorted_arr[1:]:
        if ma < a:
            n += 1
            mi, ma = a, b
        if mi < a:
            mi = a
        if ma > b:
            ma = b
    print(n)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def run():
	hasi = []
	N, M = (int(x) for x in input().split())

	for _ in range(M):
		hasi.append([int(x) for x in input().split()])
		hasi.sort()

	count = 0
	while count - 1 < len(hasi):
		ls = hasi[count]
		counter = count

		for i in hasi[1:]:
			if ls[1] <= i[0]:
				break
			else:
				hasi[count] = [i[1], min(i[1], ls[1])]
				hasi.pop(counter)
				counter += 1
		count += 1

	print(len(hasi))



if __name__ == '__main__':
	run()

Submission status: Runtime Error

Solution code:
nm = input().split()
request = []
for i in range(int(nm[1])):
    ab = input().split()
    request.append([int(ab[0]), int(ab[1])])
ans = 0
while(request != []):
    print(request)
    ans += 1
    x = request[0][0]
    y = request[0][1]
    delete = []
    delete.append(0)
    for i in request[1:]:
        if(x > i[0]):
            if(y < i[1]):
                delete.append(i)
        elif(y > i[1]):
            x = i[0]
            y = i[1]
            delete.append(i)
            
    for j in delete:
        del request[j]
print(ans-1)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np

N, req = [int(i) for i in input().split()]
A = np.array([[int(j) for j in input().split()] for i in range(req)])
diff_A = [abs(A[i][0] - A[i][1]) for i in range(req)]
bridge = np.ones(N - 1, int)
sort_diff = np.unique(np.array(sorted(diff_A)))

count = 0
for diff in sort_diff:
    for a_i in A[diff_A == diff]:
        if sum(bridge[a_i[0]:a_i[1]]) >= 1:
            bridge[list(bridge).index(1)] = 0  # 差が小さいものから] # 差が小さいものから]
            count += 1
        else:
            continue
print(count)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np

N, req = [int(i) for i in input().split()]
A = np.array([[int(j) for j in input().split()] for i in range(req)])
diff_A = [abs(A[i][0] - A[i][1]) for i in range(req)]
bridge = np.ones(N - 1, int)
sort_diff = np.unique(np.array(sorted(diff_A)))

count = 0
for diff in sort_diff:
    for a_i in A[diff_A == diff]:
        if sum(bridge[a_i[0]:a_i[1]]) >= 1:
            bridge[list(bridge).index(1)] = 0  # 差が小さいものから] # 差が小さいものから]
            count += 1
        else:
            continue
print(count)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!


N,M=map(int,input().split())
S=[]
for i in range(M):
    S.append(list(map(int,input().split())))

S1 = sorted(S, key=lambda x: x[1]-x[0])
S1.reverse()
t=0
i=0
j=0
flug=False

while M-t>0 and i<M-t-1:
    j=0
    flug=False
    while M-t>0 and j<M-t-1:
        
        if S1[i][0]<=S1[j][0] and S1[i][1]>=S1[j][1] and i!=j:
            del S1[i]
            t+=1
            print(S1)
            flug=True
            break
        j+=1
    if flug==False:
        i+=1
        
        
x=0
y=1
z=0
count=0
nagasa=len(S)

while nagasa>x+z:
    hikaku=S1[x][1]
    flug=False
    while nagasa>y+z:
        if S1[y][0]<S1[x][1]:
            del S1[y]
            z+=1
            flug=True
        if flug==False:
            y+=1
    x+=1        
            

print(len(S1))

Submission status: Runtime Error

Solution code:
#coding:utf-8

N,M = map(int,input().split())

start,left = map(int,input().split())
right = left
cnt = 0
for i in range(M-1):
    data = list(map(int,input().split()))
    if data[0] != start:
        start = data[0]
        if data[1] >= left:
            cnt += 1
            left = data[1]
            right = left
    else:
        right = data[1]
    
if data[1] >= right:
    cnt += 1

print(cnt)

Submission status: Runtime Error

Solution code:
nm = input()
n, m = nm.split()
n = int(n)
m = int(m)

arr = [[] for i in range(n)]

for i in range(m):
	ab = input()
	a, b = ab.split()
	a = int(a)
	b = int(b)
	arr[a-1].append(b)	

cnt = 0	
sting = 0
for i,isl in enumelate(arr):
	sting = isl[0]
	for j in arr[i:sting]:
		if (i == sting):
			cnt += 1
print(cnt)

Submission status: Runtime Error

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

todo = []
lis = [0 for _ in range(n+1)]

for i in range(m):
    _ = list(map(int,input().split()))
    is[_[0] -1] += 1
    lis[_[1] ] = lis[_[1] ] -1
            
    
for i in range(1,len(lis)):
    lis[i] = lis[i] + lis[i-1]
    
count  = 0
#print(lis)
for i in range(len(lis)-1):
    if lis[i]>lis[i+1] and lis[i+1] != 0:
        count += 1
    
print(count)

Submission status: Runtime Error

Solution code:
result = 0
int_n, int_m = map(int, input().split())

ar_int = list()
youbou = list()
all_youbou = list()
for i in range(int_m):
    ar_int.append(list(map(int, input().split())))


for i in ar_int:
    this_youbou = list()
    for x in range(i[0], i[1]):
        this_youbou.append((x, x + 1))
        all_youbou.append((x, x + 1))
    youbou.append(this_youbou)


while len(youbou) > 0:
    calc = sorted([[all_youbou.count(i), i] for i in set(all_youbou)],key=lambda x: x[0],reverse=True)
    w = calc[0][1]
    result = result + 1
    for y in sorted(range(int_m),reverse=True):
        if w in youbou[y]:
            youbou.pop(y)

print(result)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys
n, m = map(int, input().split())
demands = [
    tuple(map(int,
              line.strip().split())) for line in sys.stdin.readlines()
]

compressed = []
while demands:
    a, b = demands.pop()

    flag = False
    for i, (ai, bi) in enumerate(compressed):
        if b <= ai or bi <= a:
            continue

        else:
            compressed = [max(a, ai), min(b, bi)]
            break

    else:
        compressed.append([a, b])

print(len(compressed))

Submission status: Runtime Error

Solution code:
#coding:utf-8
from bisect import bisect_right

N,M = map(int,input().split())

start,left = map(int,input().split())
right = left
cnt = 0
for i in range(M-1):
    data = list(map(int,input().split()))
    if data[0] != start:
        start = data[0]
        if data[1] >= left:
            cnt += 1
            left = data[1]
            right = left
    else:
        right = data[1]
    
if data[1] >= right:
    cnt += 1

print(cnt)

Submission status: Runtime Error

Solution code:
import heapq
n, m = [int(i) for i in input().split()]
a = []
for i in range(m):
    j, k = [int(l) for l in input().split()]
    a.append([j, k])

cut = 0
heapq.heapify(a)

skip = 0
cs = a[0][0]
ce = a[0][1]
a.pop(0)

for i in range(m):
    if a[0][0] == skip:
        a.pop(0)
        continue
    if ce < a[0][0]:
        cut += 1
        cs = a[0][0]
        ce = a[0][1]
    else:
        if a[0][0] > cs:
            cs = a[0][0]
        if a[0][1] < ce:
            ce = a[0][1]
        if ce - cs == 1:
            cut += 1
            cs = 0
            ce = n+1
            skip = a[0][0]
    a.pop(0)
    if len(a) < 1:
        break

if cut == n - 1:
    print(cut)
else:
    print(cut+1)

Submission status: Runtime Error

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

Msep=[N]
Lsep=[0]

for i in range(M):
    a,b = map(int,input().split( ))
    Sep = -1
    for j in range(len(Msep)):
        if (Lsep[j]<=a) and (b<=Msep[j]):
            Sep = j
    if Sep >= 0:
        Msep.insert(j,a)
        if j < N:
            Lsep.insert(j+1,b)
    #print(Msep,Lsep)


print(len(Msep)-1)

Submission status: Runtime Error

Solution code:
# coding:utf-8

N, M = map(int, input().split())

v = []
for i in range(M):
    a, b = map(int, input().split())
    v.append([a, b])

#　print(v)

num = 0
#　aとbから最も離れた中央の橋で割るのが一番利得が大きい
cent = int((v[0][0] + v[0][1])/2)
num += 1
v_flg = [False for i in range(M)]
for i in range(len(v)):
    ai = v[i][0]
    bi = v[i][1]
    if ai <= cent and bi > cent:
        v_flg[i] = True

if all(v_flg):
    print(num)

else:
    v_new = []
    #v_flg_new = []

    for i, vf in enumerate(v_flg):
        if vf == False:
            v_new.append(v[i])
            #v_flg_new.append(False)
    #print(v_new)
    while(True):
        cent = int((v_new[0][0] + v_new[0][1])/2)
        num += 1
        pop_list = []
        for i, v_n in enumerate(v_new):
            ai = v_n[0]
            bi = v_n[1]
            if ai <= cent and bi > cent:
                #v_flg_new[i] = True
                pop_list.append(i)
        for p in pop_list:
            v_new.pop(p)

        if len(v_new) == 0:
            break

    print(num)

Submission status: Runtime Error

Solution code:
NM = list(map(int, input().split()))
#NM = [5,2]
#A = [[1,4], [2,5]]
b = list(map(int, input().split()))
#b = [[1,4]]
for i in range(NM[1]-1):
	ab = list(map(int, input().split()))
#	ab = A[i]
	flag = 1
	for i in range(len(b)):
		if (b[i][1] >= ab[0] and b[i][0] <= ab[0] ):
			b[i][0] = ab[0]
			flag = 0
			break
		if(b[i][0] <= ab[1] and b[i][1] >= ab[1]):
			b[i][1] = ab[1] 
			flag = 0
			break
		if (flag):
			b.append(ab)
			flag = 1

#print(b)
print(len(b))

Submission status: Runtime Error

Solution code:
NM = list(map(int, input().split()))
#NM = [5,2]
#A = [[1,4], [2,5]]
b = list(map(int, input().split()))
#b = [[1,4]]
for i in range(NM[1]-1):
	ab = list(map(int, input().split()))
#	ab = A[i]
	flag = 1
	for i in range(len(b)):
		if (b[i][1] >= ab[0] and b[i][0] <= ab[0] ):
			b[i][0] = ab[0]
			flag = 0
			break
		if(b[i][0] <= ab[1] and b[i][1] >= ab[1]):
			b[i][1] = ab[1] 
			print("he")
			flag = 0
			break
		if (flag):
			print("here")
			b.append(ab)
			flag = 1

#print(b)
print(len(b))

Submission status: Runtime Error

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

_a, _b = map(int, input().split())
dict_paths = {}
dict_paths[_a] = _b

for i in range(M - 1) :
    a, b = map(int, input().split())
    
    interleave_flg = False

    for k in dict_paths.keys() :
        k_tmp, k_val_tmp = k, dict_paths[k]
        
        # complete intersect
        if a >= k and b <= dict_paths[k] :
            dict_paths.pop(k)
            dict_paths[a] = b
            interleave_flg = True
            
        # nothing required
        elif a <= k and b >= dict_paths[k] :
            interleave_flg = True
            
        # left partial
        elif a < k and b > k and b <= dict_paths[k] :
            dict_paths.pop(k)
            dict_paths[a] = k_val_tmp
            interleave_flg = True
            
        # right partial
        elif a > k and a < dict_paths[k] and b >= dict_paths[k] :
            dict_paths.pop(k)
            dict_paths[k] = b
            interleave_flg = True
    
    if interleave_flg == False :
        dict_paths[a] = b
            
print(len(dict_paths))

Submission status: Runtime Error

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

todo = []
lis = [0 for _ in range(n+1)]

for i in range(m):
    if todo == []:
        todo.append(list(map(int,input().split())))
    else:
        one_input = list(map(int,input().split()))
        flag = 0
        for onepass in todo:
            if onepass[0] <= one_input[0] and one_input[1] <= onepass[0]:
                onepass = one_input
                flag = 1
                break
        if flag == 1:
            continue
        else:
            todo.append(one_input)
            
for _ in todo:
    lis[_[0] -1] += 1
    lis[_[1] ] = lis[_[1] ] -1
    
    
for i in range(1,len(lis)):
    lis[i] = lis[i] + lis[i-1]
    
count  = 0
#print(lis)
for i in range(len(lis-1)):
    if lis[i]!=lis[i+1]:
        count += 1
    
print(count)

Submission status: Runtime Error

Solution code:
import heapq
n, m = [int(i) for i in input().split()]
a = []
for i in range(m):
    j, k = [int(l) for l in input().split()]
    a.append([j, k])

cut = 0
heapq.heapify(a)

cn = a[0][0]
cs = a[0][0]
ce = a[0][1]
a.pop(0)

for i in range(m):
    if ce < a[0][0]:
        cut += 1
        cs = a[0][0]
        ce = a[0][1]
    else:
        if a[0][0] > cs:
            cs = a[0][0]
        if a[0][1] < ce:
            ce = a[0][1]
        if ce - cs == 1:
            cut += 1
            cs = 0
            ce = n+1
    a.pop(0)
    if len(a) < 1:
        break

if cut == n - 1:
    print(cut)
else:
    print(cut+1)

Submission status: Runtime Error

Solution code:
import numpy as np


N, M = map(int, input().split())

R = np.zeros([M, N-1])

for m in range(0, M):
    a, b = map(int, input().split())
    R[m, min(a, b)-1:max(a, b)-1] += 1

result = 0

while R.sum() != 0:
    R_sum = R.sum(axis=0)
    R[R[:, np.argmax(R_sum)] == 1] = 0
    result += 1

print(result)

Submission status: Runtime Error

Solution code:
import numpy as np
N, M = map(int, input().split())

a = np.zeros((M,2))

for i in range(M):
	a[i] = list(map(int, input().split()))

a = a[np.argsort(a[:,1])[::-1]]

prev = 0

a_max = 0
index = M
del_list = []
for i tmp in enumerate(a):
	if tmp[1] == prev:
		if tmp[0] > a_max:
			del_list.append(index)
			index = i
			a_max = tmp[0]
		else:
			del_list.append(i)
	else:
		prev = tmp[1]
		if tmp[0] > a_max:
			del_list.append(index)
			index = i
			a_max = tmp[0]
		elif a_max >= tmp[1]:
			a_max = tmp[0]
		else:
			del_list.append(i)
del del_list[0]
a = np.delete(a, del_list, 0)

prev = 0
b_min = N+1
index = M
del_list = []
for i, tmp in enumerate(a):
	if tmp[0] == prev:
		if tmp[1] < b_min:
			del_list.append(index)
			index = i
			b_min = tmp[1]
		else:
			del_list.append(i)
	else:
		prev = tmp[0]
		if tmp[1] < b_min:
			del_list.append(index)
			index = i
			b_min = tmp[1]
		elif b_min <= tmp[0]:
			b_min = tmp[1]
		else:
			del_list.append(i)
del del_list[0]
a = np.delete(a, del_list, 0)


a = a[np.argsort(a[:,0])]

prev = 0
b_min = N+1
index = M
del_list = []
for i, tmp in enumerate(a):
	if tmp[0] == prev:
		if tmp[1] < b_min:
			del_list.append(index)
			index = i
			b_min = tmp[1]
		else:
			del_list.append(i)
	else:
		prev = tmp[0]
		if tmp[1] < b_min:
			del_list.append(index)
			index = i
			b_min = tmp[1]
		elif b_min <= tmp[0]:
			b_min = tmp[1]
		else:
			del_list.append(i)
del del_list[0]
a = np.delete(a, del_list, 0)



ans = 0
flg = True
for i in range(len(a[:,0])-1):
	if a[i,1] > a[i+1, 0]:
		ans += 1
		flg = False
	elif flg:
		ans += 1
		flg = True
	else:
		flg = True
if flg:
	ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
def main():
        run()

def run():
        n = int(input())
        data = [int(x) for x in input().split(" ")]

        max_sum = 0 
        max_m = max(data)

        for num in data:
                max_sum += num - 1
        print(max_sum)



if __name__ == "__main__":
        main()

Submission status: Runtime Error

Solution code:
NM = list(map(int, input().split()))
b = []
for i in range(NM[1]):
	ab = list(map(int, input().split()))
	flag = 1
	for i in range(b):
		if (b[i][1] < ab[0] and b[i][0] < ab[0] ):
			b[i][0] = ab[0]
			flag = 0
			break
		if(b[i][0] > ab[1] and b[i][1] > ab[1]):
			b[i][1] = ab[1] 
			flag = 0
			break
		if (flag):
			b.append(ab)
			flag = 1

print(len(b))

Submission status: Runtime Error

Solution code:
n, m = [int(i) for i in input().split()]
a = []
for i in range(m):
    j, k = [int(l) for l in input().split()]
    a.append([j, k])

cut = 0


cn = a[0][0]
cs = a[0][0]
ce = a[0][1]
a.pop(0)

for i in range(m):
    if ce < a[0][0]:
        cut += 1
        cs = a[0][0]
        ce = a[0][1]
    else:
        if a[0][0] > cs:
            cs = a[0][0]
        if a[0][1] < ce:
            ce = a[0][1]
        if ce - cs == 1:
            cut += 1
            cs = 0
            ce = n+1
    a.pop(0)
    if len(a) < 1:
        break

if cut == n - 1:
    print(cut)
else:
    print(cut+1)

Submission status: Runtime Error

Solution code:
import numpy as np

n,m = map(int,input().split())
a = np.zeros(m)
b = np.zeros(m)
for k in range(m):
    a[k], b[k] = map(int,input().split())

c = np.vstack([a,b]).T.astype(np.int32)

def bbb(cand):
    ind = np.argmin(np.sum(cand,axis=1))
    can = cand[ind]
    cut = np.where(can == 1)[0][np.argmax(np.sum(cand[:,can == 1],axis=0))]
    remains = cand[:,cut] == 0
    remains_cut = np.arange(cand.shape[1]) != cut
    cand = cand[remains]
    try:
        cand = cand[:,remain_cuts]
    except:
        pass
    return cand

cand = np.zeros([m,n-1])
for k in range(m):
    cand[k,c[k,0] - 1 : c[k,1] - 1] = 1

cand

cut = np.sum(cand,axis=1) == 1
cut = np.sum(cand[cut],axis=0)
cuts = np.where(cut >= 1)[0]
remain_cuts = cut == 0
remains = np.sum(cand[:,cuts],axis=1) == 0
cand = cand[remains]
cand = cand[:,remain_cuts]

k = len(cuts)

while True:
    if len(cand) == 0:
        break
    cand = bbb(cand)
    k = k + 1
print(k)

Submission status: Runtime Error

Solution code:
n, m = [int(i) for i in input().split()]
a = []
for i in range(m):
    j, k = [int(l) for l in input().split()]
    a.append([j, k])

a = sorted(a)
cut = 0


cs = a[0][0]
ce = a[0][1]
a.pop(0)

for i in range(m):
    if a[0][0] > cs:
        cs = a[0][0]
    if a[0][1] < ce:
        ce = a[0][1]
    if ce - cs == 1:
        cut += 1
        cs = 0
        ce = n+1
    a.pop(0)
    if len(a) < 1:
        break

if cut == n - 1:
    print(cut)
else:
    print(cut+1)

Submission status: Runtime Error

Solution code:
import numpy as np

n,m = map(int,input().split())
a = np.zeros(m)
b = np.zeros(m)
for k in range(m):
    a[k], b[k] = map(int,input().split())

c = np.vstack([a,b]).T.astype(np.int32)

cand = np.zeros([m,n-1])
for k in range(m):
    cand[k,c[k,0] - 1 : c[k,1] - 1] = 1

cut = np.sum(cand,axis=1) == 1
cut = np.sum(cand[cut],axis=0)
cuts = np.where(cut >= 1)[0]
remain_cuts = cut == 0
remains = np.sum(cand[:,cuts],axis=1) == 0
cand = cand[remains]
cand = cand[:,remain_cuts]

k = len(cuts)

def aaa(cand):
    a = np.argmax(np.sum(cand,axis=0))
    cand = cand[cand[:,a] == 0]
    return cand,a

while True:
    if len(cand) == 0:
        break
    cand,a = aaa(cand)
    k += 1
print(k)

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
a = [0 for i in range(M)]
b = [0 for i in range(M)]
for i in range(M):
    A,B = map(int,input().split())
    a[i] = A
    b[i] = B

ans = 0
while 1:
    if len(a) == 0:
        break
    maxVal = max(a)
    if ans == 0:
        maxVal = maxVal // 2
    maxIdx = a.index(maxVal)

    for j in reversed(range(len(a))):
        if a[j] <= maxVal <= b[j] - 1:
            a.pop(j)
            b.pop(j)

    ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
N, M = map(int, input().split())
a = []
hashi = np.zeros([N - 1], dtype=int)
hozi=np.zeros([M,N - 1],dtype=int)
for i in range(M):
    a.append(list(map(int, input().split())))
    for j in range(a[i][1] - a[i][0]):
        hashi[j + a[i][0] - 1] += 1
        hozi[i][j+ a[i][0] - 1]+=1
count = 0

while (1):
    p = hashi.argmax()
    li=[]
    if hashi[p] == 0:
        break
    for i in range(hozi.shape[0]):
        if hozi[i][p] == 1:
            li.append(i)
            hashi -= hozi[i]
    hozi = np.delete(hozi, li, 0)
    count += 1
    

print(count)

Submission status: Runtime Error

Solution code:
import sys
n,m=list(map(int,input().split()))
a=[]
b=[]
for i in range(m):
    ai,bi=list(map(int,input().split()))
    a.append((ai,i))
    b.append((bi,i))

b.sort()
j=0
for i in range(m):
    if a[i]<b[j][0] or a[i]<a[b[j][1]]:
        continue
    else:
        j+=1
if b[j]>a[m-1]:
    j+=1
print(j)

Submission status: Runtime Error

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

bridge=[None]*M

for i in range(M):
    bridge[i]=tuple(map(int,input().split()))


def intersection(x,y):
    if x[1]<=y[0] or y[1]<=x[0]:
        return 0
    else:
        return {(max(x[0],y[0]),min(x[1],y[1]))}

ANS=intersection(bridge[0],bridge[1])
check=1

for i in range(2,M):
    check=1
    for j in ANS:
        if intersection(j,bridge[i])==0:
            continue
        else:
            ANS=(ANS- {j})|intersection(j,bridge[i])
            check=0
            break
    if check==1:
        ANS=ANS|{bridge[i]}
    #print(ANS)

print(len(ANS))

Submission status: Runtime Error

Solution code:
headData = [int(n) for n in input().split()]
islandNum = headData[0]
requestNum = headData[1]
requestList = []
count = 0
for n in range(requestNum):
    request = [int(elem) for elem in inpu().split()]
    requestList.append(request)


while (len(requestList) != 0):
    # 優先度チェック
    bridgePriority = islandNum * [0]
    for request in requestList:
        for j in range(request[0], request[1]):
            bridgePriority[j] += 1
    bridge = -1

    # 優先度が最も高い橋を特定
    for index in range(len(bridgePriority)):
        if (bridgePriority[index] == max(bridgePriority)):
            bridge = index
            break

    # 橋を削除した場合、叶っていないリクエストリストを作成
    newRequestList = []
    for request in requestList:
        if (bridge < request[0] or request[1] <= bridge):
            newRequestList.append(request)
    requestList = newRequestList
    count += 1

print(count)

Submission status: Runtime Error

Solution code:
import numpy as np

n,m = map(int,input().split())
a = np.zeros(m)
b = np.zeros(m)
for k in range(m):
    a[k], b[k] = map(int,input().split())

c = np.vstack([a,b]).T.astype(np.int32)

cand = np.zeros([m,n-1])
for k in range(m):
    cand[k,c[k,0] - 1 : c[k,1] - 1] = 1

temp = np.sum(cand,axis=1) != 1
k = np.sum(np.sum(cand,axis=1) == 1)
cand = cand[temp,:]

def aaa(cand):
    a = np.argmax(np.sum(cand,axis=0))
    cand = cand[cand[:,a] == 0]
    return cand,a

while True:
    if len(cand) == 0:
        break
    cand,a = aaa(cand)
    k += 1
print(k)

Submission status: Runtime Error

Solution code:
import numpy as np

n, m = list(map(int, input().split()))
ab = []
for i in range(m):
    ab.append(list(map(int, input().split())))
bridge = np.zeros((m, n-1))

for (i, (a, b)) in enumerate(ab):
    for j in range(a, b):
        bridge[i, j-1] += 1

cnt = 0
while True:
    if np.sum(bridge, axis=0).max() == 0:
        break
    max_ = np.argmax(np.sum(bridge, axis=0))
    bridge = bridge[bridge[:, max_] ==0]
    cnt += 1

print(cnt)

Submission status: Runtime Error

Solution code:
import numpy as np

S = list(map(int,input().split()))

N = S[0]
M = S[1]

pairs = [(1,N)]

island = np.zeros((N,M))
flag = np.zeros((N,M))

for count in range(0,M):
    S = list(map(int,input().split()))
    island[S[0]-1][count] = 1
    island[S[1]-1][count] = -1

flag = 0
b = 0
for count in range(0,N):
    if (island[count] == -1).any() and flag == 1:
        flag = 0
        b += 1
    if (island[count] == 1).any():
        flag = 1
        continue
        
        



print(b)

Submission status: Runtime Error

Solution code:
import numpy as np

n,m = map(int,input().split())
a = np.zeros(m)
b = np.zeros(m)
for k in range(m):
    a[k], b[k] = map(int,input().split())

c = np.vstack([a,b]).T.astype(np.int32)

cand = np.zeros([m,n-1])
for k in range(m):
    cand[k,c[k,0] - 1 : c[k,1] - 1] = 1

temp = np.sum(cand,axis=1) == 0
k = np.sum(np.sum(cand,axis=1) == 1)
cand = cand[temp,:]

def aaa(cand):
    a = np.argmax(np.sum(cand,axis=0))
    cand = cand[cand[:,a] == 0]
    return cand,a

# k = 1
while True:
    if len(cand) == 0:
        break
    cand,a = aaa(cand)
    k += 1
print(k)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
mx =[0 for i in range(0,n)]
for z in range(0,m):
  a,b=map(int,input().split())
  mx[b-1]=max(mx[b-1],a-1)
cut=0
cn=0
for z in range(0,n):
  if cut<mx[z]:
   	cut=z
    cn=cn+1
print(cn)

Submission status: Runtime Error

Solution code:
import numpy as np

n,m = map(int,input().split())
a = np.zeros(m)
b = np.zeros(m)
for k in range(m):
    a[k], b[k] = map(int,input().split())

c = np.vstack([a,b]).T.astype(np.int32)
cand = np.zeros([m,n-1])
for k in range(m):
    cand[k,c[k,0] - 1 : c[k,1] - 1] = 1

def aaa(cand):
    a = np.argmax(np.sum(cand,axis=0))
    cand_temp = cand[cand[:,a] == 0]
    return cand_temp,a

k = 1
while True:
    cand,a = aaa(cand)
    if len(cand) == 0:
        break
    k += 1
print(k)

Submission status: Runtime Error

Solution code:
import sys
n,m=list(map(int,input().split()))
a=[]
b=[]
for i in range(m):
    ai,bi=list(map(int,input().split()))
    a.append(ai)

c=b.copy()
c.sort()
j=0
if c[j]>=a[m-1]:
    print(1)
    sys.exit()

for i in range(m):
    if a[i]<c[j] or a[i]<b[j]:
        continue
    else:
        j+=1
print(j)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
mx =[0 for i in range(0,n)]
for z in range(0,m):
  a,b=map(int,input().split())
  mx[b]=max(mx[b],a)
cnt=0
cn=0
for z in range(0,n):
  if cut<mx[z]:
   	cut=z
    cn=cn+1
print(cn)

Submission status: Runtime Error

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

e.sort(key=lambda x:x[1])
ret = 0

l = 0
for i in range(m):
  if e[i][0] < l:
    continue
  else:
    l = e[i][1]
    ret += 1
    
print(ret)

Submission status: Runtime Error

Solution code:
n = raw_input()
m = int(raw_input())
ps = [map(int, raw_input().split()) for _ in range(m)]
ps.sort()
ps.reverse()
v = -1
ret = 0
for a,b in ps:
 if b <=va:
  ret += 1
  va = a
print ret