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

Solution (Python):
import sys
input = sys.stdin.readline
n,m=map(int,input().split())
l=[[0,0] for _ in range(m)]
for i in range(m):
    l[i][1],l[i][0]=map(int,input().split())

l=sorted(l)

ans=1

c=l[0][0]
for i in range(m):
    if l[i][1]>=c:
        ans+=1
        c=l[i][0]
    else:
        continue
print(ans)

Solution (Python):
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]

ab.sort(key=lambda x: x[1])

bridge_i = 0
cnt = 0
for i in range(m):
    if ab[i][0] > bridge_i:
        bridge_i = ab[i][1] - 1
        cnt += 1

print(cnt)

Solution (Python):
N,M = map(int,input().split())
bridge=[]
for i in range(M) :
    array =list(map(int,input().split()))
    bridge.append(array)
bridge =  (sorted(bridge,key=lambda x : x[1]))
result = 0
B = 0

for i in range(M):
    a, b = bridge[i]
    if a>=B :
        B=b
        result+=1

print(result)

Solution (Python):
N, M = map(int, input().split())
reqs = []
ans = 0
B = 0
for _ in range(M):
    a, b = map(int, input().split())
    reqs.append((a, b))
reqs = sorted(reqs, key=lambda x: x[1])
for i in range(M):
    a, b = reqs[i]
    if a >= B:
        B = b
        ans += 1
print(ans)

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

list_a = []
for m in range(M):
  list_a.append(list(map(int,input().split(' '))))

list_a.sort()

i = 0
cnt_break = 0
flg = False

while True:
  right = list_a[i][1]
  
  while list_a[i][0] < right:
    if i == M-1:
      flg = True
      break
    
    right = min(right,list_a[i][1])
    i += 1

  cnt_break += 1
      
  if flg:
    break
    
  
print(cnt_break)

Solution (Python):
import sys
input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    ab = sorted([list(map(int, input().split())) for i in range(M)], key=lambda x:x[1])

    B = 0
    ans = 0
    for i in range(M):
        a, b = ab[i]
        if a >= B:
            B = b
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()

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

req = []
for i in range(m):
    a,b = map(int,input().split())
    req.append([a,b])
req.sort(key=lambda x:x[1])
bef = -1
ans = 0

for i in range(m):
    if req[i][0] > bef:
        ans += 1
        bef = req[i][1]-1
    

print(ans)

Solution (Python):
def bridge_break(reqs):
    reqs.sort()
    ps = 0
    out = 0

    for req in reqs:
        if req[1] >= ps:
            out += 1
            ps = req[0]

    return out


n, m = map(int, raw_input().split())
reqs = []
for _ in range(m):
    st, end = map(int, raw_input().split())
    reqs.append((end, st))

print bridge_break(reqs)

Solution (Python):
n, m = map(int, input().split())
frontiers = {}
for i in range(m):
  a, b = map(int, input().split())
  if a in frontiers.keys():
    frontiers[a] = min(frontiers[a], b)
  else:
    frontiers[a] = b

cuts = 0
frontier = 10**6

for i in range(1, n):
  if i in frontiers.keys():
    frontier = min(frontier, frontiers[i])
  if i + 1 == frontier:
    cuts += 1
    frontier = 10**6
    
print(cuts)

Solution (Python):
n, m = map(int, input().split())
wars = {}
for i in range(m):
  a, b = map(int, input().split())
  if a in wars.keys():
    wars[a] = min(wars[a], b)
  else:
    wars[a] = b

cuts = 0
antis = 10**6

for i in range(1, n):
  if i in wars.keys():
    antis = min(antis, wars[i])
  if i + 1 == antis:
    cuts += 1
    antis = 10**6
    
print(cuts)

Solution (Python):
from operator import itemgetter
n, m = map(int, input().split())

ab = [tuple(map(int, input().split())) for i in range(m)]

ab = sorted(ab, key=itemgetter(1))

count = 0
cut = 0
for i in range(m):
    if cut <= ab[i][0]:
        count += 1
        cut = ab[i][1]

print(count)

Solution (Python):
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(m)]
ab.sort(key=lambda x:x[1])
x=0
ans=0
for i in range(m):
    a,b=ab[i][0],ab[i][1]
    if a>x:
        x=b-1
        ans+=1
    else:
        continue
print(ans)

Solution (Python):
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(M)]
ab.sort(key = lambda x:x[1])
point = 0 
cnt = 0
for a, b in ab:
  if a < point:
    continue
  else:
    cnt += 1
    point = b
print(cnt)