GBC

발자·2023년 5월 10일
0

Softeer

목록 보기
7/17

문제

# N : 각 구간의 길이 및 해당 구간에서의 제한 속도
# M : 테스트하는 구간의 길이와 속도
N, M = map(int, input().split())

# 구간 및 제한 속도
standard = []

# N개의 줄
for i in range(N):
    standard.append(list(map(int, input().split())))

# 테스트 구간 및 속도
test = []

# M개의 줄
for i in range(M):
    test.append(list(map(int, input().split())))

# 제한 속도를 가장 크게 벗어난 값
max_speed = 0

# standard 리스트의 index
i = 0
# test 리스트의 index
j = 0

while i < N and j < M:
    # standard i번째, test j번째 값 저장
    [section, speed] = standard[i]
    [test_section, test_speed] = test[j]
    # 가장 큰 값으로 저장
    max_speed = max(max_speed, test_speed - speed)
    # 남은 구간 계산산
    standard[i][0] = section - min(section, test_section)
    test[j][0] = test_section - min(section, test_section)
    # 남은 구간으로 i, j 판단
    if standard[i][0] > 0 and test[j][0] == 0:
        j += 1
    elif standard[i][0] == 0 and test[j][0] > 0:
        i += 1
    else:
        i += 1
        j += 1
print(max_speed)

0개의 댓글