adding python solution
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -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": [],
|
||||
|
||||
29
inclusao-de-subintervalos/src/saad.py
Normal file
29
inclusao-de-subintervalos/src/saad.py
Normal 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()
|
||||
Reference in New Issue
Block a user