# 지름길 import sys input = sys.stdin.readline def solution(): n, d = map(int, input().rstrip().split()) shortcut = {} for _ in range(n): start, end, cost = map(int, input().rstrip().split()) if end > d: continue if not shortcut.get(end, []): shortcut[end] = [] shortcut[end].append((start, cost)) dp = [0] * (d+1) for i in range(1, d+1): shortcut_list = shortcut.get(i, []) dp[i] = min(min([dp[s]+c for s, c in shortcut_list]) if shortcut_list else float('inf'), dp[i-1]+1) print(dp[d]) return solution() """ 걸린 시간: 30분 시간 복잡도: 모든 지점에 대해 dp 값을 구하는데, 이때 한 지점은 연결된 지름길만큼 반복한다. 하지만 지름길 하나 당 한번만 보기 때문에 전체 시간복잡도는 O(n+d)이다. 해설: 지름길의 도착 위치 기준으로 그냥 가는 것과 여러 지름길 중 하나를 선택하는 것과 같이 여러 개를 비교해야했다. 그리고 비교를 하는 것이 과거의 지점에서 계산을 하는 것이기 때문에 dp를 생각했다. 현재 지점의 dp를 계산할 때 이 곳에 올 수 있는 모든 경우의 수 중 cost가 최소인 것을 구하면 된다. 따라서 지름길을 통해 오는 것과 바로 한 칸 전 위치에서 +1로 오는 경우 중 구하면 된다. """