You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mycode/ACM/值周.py

28 lines
647 B

import functools
a,b =map(int, input().split(' '))
nums=[]
for i in range(b):
m,n=map(int,input().split(' '))
if m>n:continue;
nums.append([m,n])
def cmp(a,b):#升序
if(a[0]>b[0]):
return 1
else :
return -1#不变
nums=sorted(nums,key=functools.cmp_to_key(cmp))
# for i in nums:
# print(i)
sum = 0
start,end=nums[0][0],nums[0][1]
count=1
while count<len(nums):
if nums[count][0]>=start and nums[count][0]<=end:
if end<=nums[count][1]:
end=nums[count][1]
else :
sum+=end-start+1
start=nums[count][0];end=nums[count][1]
count+=1
sum+=end-start+1
print(a-sum+1)