| Task: | Binge watching |
| Sender: | aalto25b_009 |
| Submission time: | 2025-09-10 16:51:25 +0300 |
| Language: | Python3 (PyPy3) |
| Status: | READY |
| Result: | ACCEPTED |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.04 s | details |
| #2 | ACCEPTED | 0.04 s | details |
| #3 | ACCEPTED | 0.04 s | details |
| #4 | ACCEPTED | 0.65 s | details |
| #5 | ACCEPTED | 0.36 s | details |
| #6 | ACCEPTED | 0.66 s | details |
| #7 | ACCEPTED | 0.04 s | details |
| #8 | ACCEPTED | 0.04 s | details |
| #9 | ACCEPTED | 0.04 s | details |
Code
n = int(input())
movies = []
for i in range(n):
a, b = map(int, input().split())
movies.append([a, b])
def max_non_overlapping_intervals(intervals):
# Sort intervals by their end times
intervals.sort(key=lambda x: x[1])
# Initialize the end time of the last selected interval
end = float('-inf')
# Initialize the count of non-overlapping intervals
count = 0
# Iterate through the sorted intervals
for interval in intervals:
# If the start time of the current interval is greater than or equal to the end time of the last selected interval
if interval[0] >= end:
# Select this interval
end = interval[1]
# Increment the count
count += 1
return count
print(max_non_overlapping_intervals(movies))Test details
Test 1
Verdict: ACCEPTED
| input |
|---|
| 10 6 7 4 5 8 9 2 3 ... |
| correct output |
|---|
| 10 |
| user output |
|---|
| 10 |
Test 2
Verdict: ACCEPTED
| input |
|---|
| 10 1 1000 1 1000 1 1000 1 1000 ... |
| correct output |
|---|
| 1 |
| user output |
|---|
| 1 |
Test 3
Verdict: ACCEPTED
| input |
|---|
| 10 404 882 690 974 201 255 800 933 ... |
| correct output |
|---|
| 4 |
| user output |
|---|
| 4 |
Test 4
Verdict: ACCEPTED
| input |
|---|
| 200000 177494 177495 157029 157030 6030 6031 15209 15210 ... |
| correct output |
|---|
| 200000 |
| user output |
|---|
| 200000 |
Test 5
Verdict: ACCEPTED
| input |
|---|
| 200000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 ... |
| correct output |
|---|
| 1 |
| user output |
|---|
| 1 |
Test 6
Verdict: ACCEPTED
| input |
|---|
| 200000 82334756 323555178 958182284 981100325 649818003 678160906 801994655 889397498 ... |
| correct output |
|---|
| 725 |
| user output |
|---|
| 725 |
Test 7
Verdict: ACCEPTED
| input |
|---|
| 3 1 1000 2 3 5 6 |
| correct output |
|---|
| 2 |
| user output |
|---|
| 2 |
Test 8
Verdict: ACCEPTED
| input |
|---|
| 3 3 4 5 6 7 8 |
| correct output |
|---|
| 3 |
| user output |
|---|
| 3 |
Test 9
Verdict: ACCEPTED
| input |
|---|
| 2 1 2 3 4 |
| correct output |
|---|
| 2 |
| user output |
|---|
| 2 |
