Train

시간 제한1초메모리 제한1024 MB

요약
행성 간 기차 노선의 시간과 요금, 행성별 식사 비용이 주어질 때, 정해진 시간 구간 안에서 W끼의 식사를 하며 행성 N-1에 도착하는 최소 비용을 구한다.
난이도

어려움10점 중 8점

유형
그래프, 최단 경로, 동적 계획법, 정렬
정답자
아직 제출이 없습니다

문제

In the year 2992, most jobs have been taken by robots. Many people hence have abundant free time, and so is your family, who just decided to go for interstellar travel!

There are NN reachable planets indexed from 00 to N−1N - 1 and MM interstellar train routes. The train route ii (0≤i<M0 ≤ i < M) starts from Planet X\[i]X\[i] at time A\[i]A\[i], arrives in Planet Y\[i]Y\[i] at time B\[i]B\[i], and costs C\[i]C\[i]. Trains are the only transportation between planets, so you can only get off a train on its destination planet, and must take the next train on the same planet (transfers take no time). Formally, a sequence of trains q\[0],q\[1],…,q\[P]q\[0], q\[1], \dots, q\[P] is valid to be taken if and only if for any 1≤k≤P1 ≤ k ≤ P, Y\[q\[k−1]]=X\[q\[k]]Y \[q\[k - 1]] = X\[q\[k]] and B\[q\[k−1]]≤A\[q\[k]]B\[q\[k - 1]] ≤ A\[q\[k]].

As interstellar travel is time-consuming, you realize that in addition to the train fare, the cost of meals is significant. Thankfully, interstellar trains provide unlimited food for free. That is, if you decide to take train route ii, then at any time between A\[i]A\[i] and B\[i]B\[i] (inclusive) you can take any number of meals with no cost. But while your family is waiting for the next train on any Planet ii, you have to pay for each meal at the cost T\[i]T\[i].

Your family need to have WW meals, and the ii-th (0≤i<W0 ≤ i < W) meal can be taken instantenously at any time between L\[i]L\[i] and R\[i]R\[i] (inclusive).

Now at time 00, your family are on Planet 00. You need to figure out the minimum cost to reach Planet N−1N - 1. If you cannot reach there, your answer should be −1-1.

제한

  • 2≤N≤1052 ≤ N ≤ 10^5.
  • 0≤M,W≤1050 ≤ M,W ≤ 10^5.
  • 0≤X\[i],Y\[i]<N0 ≤ X\[i],Y \[i] < N, X\[i]≠Y\[i]X\[i] \ne Y\[i].
  • 1≤A\[i]<B\[i]≤1091 ≤ A\[i] < B\[i] ≤ 10^9.
  • 1≤T\[i],C\[i]≤1091 ≤ T\[i],C\[i] ≤ 10^9.
  • 1≤L\[i]≤R\[i]≤1091 ≤ L\[i] ≤ R\[i] ≤ 10^9.

예제

이 문제는 공개된 예제가 없습니다.