Untitled

mail@pastecode.io avatar
unknown
python
2 years ago
589 B
6
Indexable
Never
def calculate(flowers):
    result = [flowers[0]]
    for flower in flowers[1::]:
        if result[-1][0] <= flower[0] <= result[-1][1] < flower[1]:
            result[-1][1] = flower[1]
        elif flower[0] <= result[-1][0] or flower[1] <= result[-1][1]:
            pass
        else:
            result.append(flower)
    return result


def main():
    n = int(input())
    flowers = [list(map(int, input().split())) for i in range(n)]
    flowers = sorted(flowers)
    for flow in calculate(flowers):
        print(flow)


if __name__ == '__main__':
    main()