DJ Gigs

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

요약
가중 그래프로 연결된 소수의 공연장과 시간 구간별 보상이 주어질 때, 이동 시간을 고려해 겹치지 않게 공연을 골라 최대 수익을 구한다.
난이도

어려움10점 중 8점

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

문제

Doug James is an up-and-coming DJ from Graphland who’s had a tough time making it big. This all changed with the release of his latest EP Wiggly Waves, which is the first album in history to go both Platinum and Uranium. With his newfound popularity, Doug (a.k.a. DJ Polygon) needs help with a problem most artists would be lucky to face: deciding which of his many gig offers to take.

There are KK venues in Graphland, connected by RR roads. The venues are numbered 11 to KK. Doug’s house is venue 11, and he is ready to leave or perform at time t=0t = 0.

Doug has GG gig offers. The ii-th gig is at venue V_iV\_ i, runs during the time interval \[S_i,E_i)\[S\_ i,E\_ i) (inclusive start, exclusive end), and pays out M_iM\_ i cryptocents. Doug can’t take multiple gigs at the same time, and he can’t take gigs while he’s traveling between venues.

Doug is overwhelmed by his newfound fame and many gig requests, and wants your help making as much money as possible.

입력

The first line of the input contains three integers GG, KK, and RR: the number of gigs Doug has been offered, the number of venues in Graphland, and the number of roads connecting these venues.

These integers satisfy 1≤G≤200,0001 \leq G \leq 200\\, 000, 1≤K≤1001 \leq K \leq 100, and 0≤R≤min⁡(4,000,K(K−1)/2)0 \leq R \leq \min \left(4\\, 000, K(K-1)/2\right).

Then follow RR lines, each of which has three integers A_iA\_ i, B_iB\_ i, and T_iT\_ i, specifying the ii-th (bidirectional) road. The ii-th road connects venues A_iA\_ i and B_iB\_ i and it takes time T_iT\_ i to travel the road in either direction. The values satisfy 1≤A_i,B_i≤K1 \leq A\_ i, B\_ i \leq K, A_i≠B_iA\_ i \neq B\_ i, and 1≤T_i≤1,000,0001 \leq T\_ i \leq 1\\, 000\\, 000. Every road has two distinct endpoints, and there is at most one road between any pair of venues.

Then follow GG lines, each of which has four integers V_iV\_ i, S_iS\_ i, E_iE\_ i, and M_iM\_ i. This means the ii-th gig runs from time S_iS\_ i (inclusive) to E_iE\_ i (exclusive) at venue V_iV\_ i, and pays M_iM\_ i cryptocents. These values satisfy the bounds 0≤S_i<E_i≤1,000,000,0000 \leq S\_ i < E\_ i \leq 1\\, 000\\, 000\\, 000 and 1≤M_i≤1,000,0001 \leq M\_ i \leq 1\\, 000\\, 000.

출력

Output a single integer: the maximum number of cryptocents that DJ Polygon can make by taking on the right gigs.

힌트

In the first sample, There are two gigs at venue 11 and one gig at venue 22. Doug can either play both gigs at venue 11 for 1111 cryptocents, or spend the first 1010 units of time traveling to venue 22 and play that gig for 3333 cryptocents. He chooses the latter.

In the second sample, Doug makes the most by staying at venue 11 and playing both of those gigs to earn 7070 cryptocents.

예제2

  1. 예제 1

    입력
    3 2 1
    1 2 10
    1 4 6 6
    1 6 10 5
    2 10 30 33
    
    예상 출력
    33
    
  2. 예제 2

    입력
    3 2 1
    1 2 10
    1 4 6 30
    1 6 10 40
    2 10 30 50
    
    예상 출력
    70