Created
February 16, 2019 13:29
-
-
Save racterub/a9c5526f7993ceaf2caa89df5e529e96 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
# @Date : 2019-02-16 08:59:40 | |
# @Author : Racter ([email protected]) | |
# @Profile : https://racterub.me | |
# OJ: https://zerojudge.tw/ShowProblem?problemid=b966 | |
while 1: | |
try: | |
count = int(input().strip()) | |
data = [list(map(int, input().strip().split(' '))) for i in range(count)] | |
data = sorted(data, key=lambda v:v[1]) # sorted with start value to prevent data needs to jump to different block back and forth | |
s = data[0][0] | |
e = data[0][1] | |
length = e-s | |
for i in data[1:]: | |
if i[0] < e and i[1] > e: | |
e = i[1] | |
elif i[0] > e: | |
length += (e-s) | |
s = i[0] | |
e = i[1] | |
print(length) | |
except EOFError: | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment