DJ Gigs
InterviewTime limit8sMemory limit1024 MB
Doug starts at venue 1 at time 0 and picks non-overlapping gigs, accounting for road travel times between venues, to maximize total pay.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Shortest path, Sorting, Binary search
- Solved
- No attempts yet
Problem
Doug James is an up-and-coming DJ from Graphland who has had a tough time making it big. That changed when his latest EP Wiggly Waves became the first album in history to go both Platinum and Uranium. With his newfound popularity, Doug (a.k.a. DJ Polygon) has a problem most artists would envy: he must decide which of his many gig offers to accept.
There are venues in Graphland, connected by roads. The venues are numbered to . Doug's house is venue , and he is ready to leave or perform at time .
Doug has gig offers. The -th gig is at venue , runs during the time interval (inclusive start, exclusive end), and pays cryptocents. Doug cannot take multiple gigs at the same time, and he cannot take gigs while he is traveling between venues.
Doug is overwhelmed by his fame and the many gig requests, so he wants your help making as much money as possible.
Input
The first line contains three integers , , and : the number of gigs, the number of venues, and the number of roads. These satisfy , , and .
Each of the next lines contains three integers , , and , describing the -th bidirectional road. It connects venues and , and it takes time to travel the road in either direction. The values satisfy , , and . There is at most one road between any pair of venues.
Each of the next lines contains four integers , , , and . The -th gig runs from time (inclusive) to (exclusive) at venue and pays cryptocents. These values satisfy and .
Output
Output a single integer: the maximum number of cryptocents Doug can earn by taking the right gigs.
Hints
In the first sample, there are two gigs at venue and one gig at venue . Doug can either play both gigs at venue for cryptocents, or spend the first units of time traveling to venue and play that gig for cryptocents. He chooses the latter.
In the second sample, Doug earns the most by staying at venue and playing both gigs for cryptocents.