Movie Festival
Explanation
In this problem, we have n
movies and their starting and ending times. We need to find out how many maximum movies we can watch, if we watch each movie completely.
We can do this by sorting all movies by their ending times. Then we'll watch movies that end the earliest. This way we'll be able to watch the maximum movies.
Code
import sys
input = sys.stdin.readline
movies = []
for _ in range(int(input())):
a, b = map(int, input().split())
movies.append((b, a))
movies.sort()
count = 0
last = 0
for b, a in movies:
if a >= last:
count += 1
last = b
print(count)