nq1s788

26 пересечение отрезков (событий)

Apr 20th, 2025 (edited)
544
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. #https://postimg.cc/QF0kY2vL
  2. data = open('26.txt').readlines()
  3. n = int(data[0])
  4. a = []
  5. for e in data[1:]:
  6.     l, r = map(int, e.split())
  7.     a.append((r, l))
  8. a.sort()
  9. answ = [a[0]]
  10. for i in range(1, n):
  11.     if a[i][1] - answ[-1][0] >= 15: #начало следующего минус конец последнего взятого
  12.         answ.append(a[i])
  13. print(len(answ))
  14. t = answ[-2][0] #конец предпоследнего отрезка
  15. mx = 0
  16. for e in a: #перебираем все отрезки
  17.     if e[1] - t >= 15: #если отрезок начинается хотя бы на 15 минут позже предпоследнего
  18.         mx = max(e[1], mx)
  19. print(mx - t)
Advertisement
Add Comment
Please, Sign In to add comment