adding python solution

This commit is contained in:
2026-05-20 14:50:19 -03:00
parent 33d87c5809
commit 8785966987
4 changed files with 45 additions and 5 deletions

View File

@@ -11,10 +11,14 @@
"grader": false,
"subject": {
"en_us": [
"set-cover-problem", "greedy", "sorting"
"set-cover-problem",
"greedy",
"sorting"
],
"pt_br": [
"inclusao-de-subintervalos", "guloso", "ordenação"
"inclusao-de-subintervalos",
"guloso",
"ordenação"
],
"es": [
""
@@ -43,9 +47,16 @@
},
"solutions": {
"main-ac": "ac.cpp",
"alternative-ac": ["caio.cpp"],
"wrong-answer": ["wa.cpp"],
"time-limit": ["TLE.cpp"],
"alternative-ac": [
"caio.cpp",
"saad.py"
],
"wrong-answer": [
"wa.cpp"
],
"time-limit": [
"TLE.cpp"
],
"time-limit-or-ac": [],
"time-limit-or-memory-limit": [],
"memory-limit": [],

View File

@@ -0,0 +1,29 @@
import sys
def main() -> None:
data = list(map(int, sys.stdin.buffer.read().split()))
n = data[0]
intervals = []
index = 1
for _ in range(n):
left = data[index]
right = data[index + 1]
intervals.append((left, right))
index += 2
intervals.sort(key=lambda interval: (interval[0], -interval[1]))
last_covered = intervals[0][1]
count = 1
for _, right in intervals[1:]:
if last_covered < right:
last_covered = right
count += 1
sys.stdout.write(f"{count}\n")
if __name__ == "__main__":
main()