Softeer: GBC
2021. 10. 13. 17:59ㆍAlgorithm
- 목차
반응형
O(N) algorithm
import sys
import bisect
limits = []
test = []
N, M = map(int, sys.stdin.readline().split())
for i in range(N):
limits += list(map(int, sys.stdin.readline().split())),
for i in range(M):
test += list(map(int, sys.stdin.readline().split())),
for i in range(len(limits) - 1):
limits[i + 1][0] += limits[i][0]
for i in range(len(test) - 1):
test[i + 1][0] += test[i][0]
mx = 0
for end, speed in test:
while limits and limits[0][0] < end:
if speed > limits[0][1]:
mx = max(speed - limits[0][1], mx)
limits.pop(0)
if limits and end <= limits[0][0]:
if speed > limits[0][1]:
mx = max(speed - limits[0][1], mx)
if limits and limits[0][0] == end:
limits.pop(0)
print(mx)
반응형
'Algorithm' 카테고리의 다른 글
Softeer: 징검다리2 (0) | 2021.10.14 |
---|---|
Softeer: H-클린알파 (0) | 2021.10.13 |
2027. Minimum Moves to Convert String (0) | 2021.10.10 |
GINI야 도와줘 (0) | 2021.10.09 |
softeer: 동계 테스트 시점 예측 (0) | 2021.10.08 |