20分求助!能看看有什么问题不

P1047 [NOIP2005 普及组] 校门外的树

zchu @ 2023-04-29 14:23:28

l,m = map(int,input().split())
tree = l+1
region = []
for i in range(m) :
    u,v = map(int,input().split())
    region.append([u,v])
region.sort(reverse=False)
for i in range(m-1) :
    if region[i][1]>region[i+1][0] :
        region[i][1] = region[i+1][0]-1
for i in range(m) :
    cut = region[i][1]-region[i][0]+1
    tree = tree-cut
print(tree)  

|