Problem: 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.

Submission attempts (in order):
ab=[]

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

for i in range(m):
    ab.append(tuple(map(int,input().split())))

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

res=0
milestone=0
while(1):
    for j in range(1,len(ab)):
        if ab[0][1] < ab[j][0]:
          milestone=j
          res+=1
          break
    del ab[:milestone]
    if len(ab)==1:
        res+=1
        del ab[0]
    if len(ab)==0:
        break

print(res)

ab=[]
n,m = map(int,input().split())

for i in range(m):
    ab=(map(int,input().split()))

abr=[]
enabled=[]
removed=[]
for i in range(m):
    abr.append(range(ab[i][0],ab[i][1]))
    enabled.append(False)
    removed.append(False)

res=0
for i in range(n):
    for j in range(len(abr)):
        if i == abr[j][0] and not removed[j]:
            enabled[j]=True
    for j in range(len(abr)):
        if i == abr[j][-1]:
            res+=1
            for k in range(len(abr)):
                if enabled[j]:
                    enabled[j]=False
                    removed[j]=True
print(res)

ab=[]

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

for i in range(m):
    ab.append(tuple(map(int,input().split())))

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

res=0
mark=0
for z in range(len(ab)):
    x=ab[0][1]
    for j in range(len(ab)):
        if x > ab[j][0]:
            pass
        else:
            mark=j
            break
    if len(ab[:mark])>0:
        res+=1
        del ab[:mark]
    if len(ab)==0:
        break
    
print(res)

ab=[]

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

for i in range(m):
    ab.append(tuple(map(int,input().split())))

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

res=0
milestone=0
while(1):
    for j in range(len(ab)):
        if ab[0][1] < ab[j][0]:
          milestone=j
          res+=1
          break
    del ab[:milestone]
    if len(ab)==1:
        res+=1
        ab.remove(0)
    if len(ab)==0:
        break

print(res)

ab=[]

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

for i in range(m):
    ab.append(tuple(map(int,input().split())))

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

res=0
for z in range(len(ab)): 
    mark=0
    x=ab[0][1] 
    if x==ab[-1][1]:
        res+=1
        print("last")
        del ab[:]
        #break
    for j in range(len(ab)):
        if x > ab[j][0]:
            pass
        else:
            mark=j
            break
    if len(ab[:mark])>0:
        print("mark")
        res+=1
        del ab[:mark]
    print(res,x,mark,ab)
    if len(ab)==0:
        break
    
print(res)

ab=[]

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

for i in range(m):
    ab.append(tuple(map(int,input().split())))

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

res=0
for z in range(len(ab)):
    mark=0
    x=ab[0][1]
    if x==ab[-1][1]:
        res+=1
        del ab[:]
    for j in range(len(ab)):
        if x > ab[j][0]:
            pass
        else:
            mark=j
            break
    if len(ab[:mark])>0:
        res+=1
        del ab[:mark]
    if len(ab)==0:
        break
    
print(res)

ab=[]

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

for i in range(m):
    ab.append(tuple(map(int,input().split())))

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

res=0
mark=0
while(1):
    for j in range(len(ab)):
        if abrs[0][1] > ab[j][0]:
            pass
        else:
            if mark!=j:res+=1
            mark=j
            break
    del ab[:mark]
    if len(ab)==0:
        res+=1
        break

    for j in range(len(abrs)):
        if ab[0][0] > abrs[j][0]:
            pass
        else:
            mark=j
            break
    del abrs[:mark]
    
print(res)

ab=[]

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

for i in range(m):
    ab.append(tuple(map(int,input().split())))

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

res=0
for z in range(len(ab)): 
    mark=0
    x=ab[0][1] 
    if x==ab[-1][1]:
        res+=1
        del ab[:]
        #break
    for j in range(len(ab)):
        if x > ab[j][0]:
            pass
        else:
            mark=j
            break
    if len(ab[:mark])>0:
        res+=1
        del ab[:mark]
    if len(ab)==0:
        break
    
print(res)

ab=[]

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

for i in range(m):
    ab.append(tuple(map(int,input().split())))

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

res=0
mark=0
while(1):
    for j in range(len(ab)):
        if abrs[0][1] > ab[j][0]:
            pass
        else:
            if mark!=j:res+=1
            mark=j
            break
    del ab[:mark]
    if len(ab)==1:
        res+=1
        break
    for j in range(len(abrs)):
        if ab[0][0] > abrs[j][0]:
            pass
        else:
            mark=j
            break
    del abrs[:mark]
    
print(res)

ab=[]

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

for i in range(m):
    ab.append(tuple(map(int,input().split())))

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

res=0
mark=0
while(1):
    for j in range(len(ab)):
        if abrs[0][1] > ab[j][0]:
            pass
        else:
            mark=j
            break
    if len(ab[:mark])>0:res+=1
    del ab[:mark]
    if len(ab)==0:
        break
    for j in range(len(abrs)):
        if ab[0][0] > abrs[j][0]:
            pass
        else:
            mark=j
            break
    del abrs[:mark]
    
print(res)

ab=[]

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

for i in range(m):
    ab.append(tuple(map(int,input().split())))

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

res=0
milestone=0
while(1):
    for j in range(len(ab)):
        if ab[0][1] < ab[j][0]:
          milestone=j
          res+=1
          break
    del ab[:milestone]
    if len(ab)==1:
      res+=1
      ab.remove(0)
    if len(ab)==0
      break

print(res)

ab=[]

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

for i in range(m):
    ab.append(tuple(map(int,input().split())))

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

res=0
for z in range(len(ab)):
    x=ab[0][1]
    if x==ab[-1][1]:
        res+=1
        break
    for j in range(len(ab)):
        if x > ab[0][0]:
            del ab[0]
            if len(ab)==0:
                res+=1
                break
        else:
            res+=1
            break
    
print(res)

ab=[]

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

for i in range(m):
    ab.append(tuple(map(int,input().split())))

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

res=0
mark=0
while(1):
    for j in range(len(ab)):
        if abrs[0][1] > ab[j][0]:
            pass
        else:
            mark=j
            break
    if len(ab[:mark])>0:res+=1
    del ab[:mark]
    if len(ab)==0:
        break
    for j in range(len(abrs)):
        if ab[0][0] > abrs[j][0]:
            pass
        else:
            mark=j
            break
    del abrs[:mark]
    
print(res)

ab=[]

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

for i in range(m):
    ab.append(tuple(map(int,input().split())))

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

res=0
for z in range(len(ab)):
    x=ab[0][1]
    if x==ab[-1][1]:
        res+=1
        break
    for j in range(len(ab)):
        if x > ab[0][0]:
            del ab[0]
        else:
            res+=1
            break
    if len(ab)==0:
        break
    
print(res)

ab=[]

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

for i in range(m):
    ab.append(tuple(map(int,input().split())))

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

res=0
index=0
toremove=set()
while(1):
    for j in range(index,len(ab)):
        if ab[index][1] < ab[j][0]:
          index=j
          res+=1
          break
    if index == len(ab):break

print(res)

ab=[]

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

for i in range(m):
    ab=(map(int,input().split()))


abr=[]
enabled=[]
removed=[]
for i in range(m):
    abr.append(range(ab[i][0],ab[i][1]))
    enabled.append(False)
    removed.append(False)

res=0
for i in range(n):
    for j in range(len(abr)):
        if i == abr[j][0] and not removed[j]:
            enabled[j]=True
    for j in range(len(abr)):
        if i == abr[j][-1] and enabled[j]:
            res+=1
            for k in range(len(abr)):
                if enabled[k] and not removed[k]:
                    enabled[k]=False
                    removed[k]=True

print(res)

ab=[]

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

for i in range(m):
    ab.append(tuple(map(int,input().split())))

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

res=0
mark=0
for i in range(len(abrs)):
    for j in range(len(ab)):
        if abrs[i][1] > ab[j][0]:
            pass
        else:
            if mark!=j:
                res+=1
            mark=j
            break
    del ab[:mark]
    if len(ab)==1:
        break

print(res)

ab=[]

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

for i in range(m):
    ab.append(tuple(map(int,input().split())))

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

res=0
milestone=0
while(1):
    for j in range(len(ab)):
        if ab[0][1] < ab[j][0]:
          milestone=j
          res+=1
          break
    del ab[:milestone]
    if len(ab)==0:break

print(res)

ab=[]

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

for i in range(m):
    ab.append(tuple(map(int,input().split())))

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

res=0
mark=0
for z in range(len(ab)):
    x=ab[0][1]
    mark=0
    for j in range(len(ab)):
        if x > ab[j][0]:
            pass
        else:
            mark=j
            break
    if len(ab[:mark])>0:
        res+=1
        del ab[:mark]
    if len(ab)==0:
        break
    
print(res)

ab=[]

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

for i in range(m):
    ab.append(tuple(map(int,input().split())))

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

res=0
for z in range(len(ab)): 
    mark=0
    x=ab[0][1] 
    if x==ab[-1][1]:
        res+=1
        del ab[:]
        break
    for j in range(len(ab)):
        if x > ab[j][0]:
            pass
        else:
            mark=j
            break
    if len(ab[:mark])>0:
        res+=1
        del ab[:mark]
    if len(ab)==0:
        break
    
print(res)

ab=[]

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

for i in range(m):
    ab.append(tuple(map(int,input().split())))

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

res=0
mark=0
while(1):
    for j in range(len(ab)):
        if abrs[0][1] > ab[j][0]:
            pass
        else:
            if mark!=j:res+=1
            mark=j
            break
    del ab[:mark]
    if len(ab)==0:
        res+=1
        break
    for j in range(len(abrs)):
        if ab[0][0] > abrs[j][0]:
            pass
        else:
            mark=j
            break
    del abrs[:mark]
    
print(res)

ab=[]

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

for i in range(m):
    ab.append(tuple(map(int,input().split())))
ab.sort(key=lambda x:x[1])

print(ab)

res=0
mark=0
for z in range(len(ab)):
    x=ab[0][1]
    for j in range(len(ab)):
        if x > ab[j][0]:
            pass
        else:
            mark=j
            break
    if len(ab[:mark])>0:
        print("mark")
        res+=1
        del ab[:mark]
    print(res,x,mark,ab)
    if len(ab)==0:
        break
    
print(res)

ab=[]

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

for i in range(m):
    ab.append(tuple(map(int,input().split())))

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

res=0
milestone=0
while(1):
    for j in range(len(ab)):
        if ab[0][1] < ab[j][0]:
          milestone=j
          res+=1
          break
    del ab[:milestone]
    if len(ab)==1:
      res+=1
      break

print(res)

ab=[]

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

for i in range(m):
    ab.append(tuple(map(int,input().split())))

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

res=0
mark=0
for z in range(len(ab)):
    x=ab[0][1]
    for j in range(len(ab)):
        if x > ab[j][0]:
            pass
        else:
            mark=j
            break
    if len(ab[:mark])>0:
        res+=1
        del ab[:mark]
    if len(ab)==0:
        break
    
print(res)

ab=[]

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

for i in range(m):
    ab.append(tuple(map(int,input().split())))

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

res=0
mark=0
for z in range(len(ab)):
    x=ab[0][1]
    mark=0
    if x==ab[-1][1]:
        res+=1
        break
    for j in range(len(ab)):
        if x > ab[0][1]:
            del ab[0][1]
        else:
            res+=1
            break
    if len(ab)==0:
        break
    
print(res)

ab=[]

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

for i in range(m):
    ab.append(tuple(map(int,input().split())))

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

res=0
milestone=0
while(1):
    for j in range(len(ab)):
        if ab[0][1] < ab[j][0]:
          milestone=j
          res+=1
          break
    ab.remove[0:milestone]
    if len(ab)==0:break

print(res)

ab=[]

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

for i in range(m):
    ab.append(tuple(map(int,input().split())))

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

res=0
mark=0
for z in range(len(ab)):
    x=ab[0][1]
    mark=0
    if x==ab[-1][1]:
        res+=1
        break
    for j in range(len(ab)):
        if x > ab[j][0]:
            pass
        else:
            mark=j
            break
    if len(ab[:mark])>0:
        res+=1
        del ab[:mark]
    if len(ab)==0:
        break
    
print(res)

ab=[]

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

for i in range(m):
    ab.append(tuple(map(int,input().split())))

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

res=0
for z in range(len(ab)):
    x=ab[0][1]
    for j in range(len(ab)):
        if x > ab[0][0]:
            del ab[0]
        else:
            res+=1
            break
    if len(ab)==0:
        res+=1
        break
    
print(res)

Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Runtime Error

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Wrong Answer

Runtime Error

Runtime Error

Wrong Answer

Wrong Answer

Time Limit Exceeded

Runtime Error

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Wrong Answer

Accepted