Shimmer Production
Time limit2.5sMemory limit1024 MB
Pick at most k machines, each reached by shortest path from vertex 1, so that V components finish as early as possible; output that minimum time.
- Level
Medium7 of 10
- Topics
- Shortest path, Binary search, Greedy
- Solved
- No attempts yet
Problem
Silco needs special machines to synthesize Shimmer. Before using them, the machines must be obtained in the city and delivered to the factory.
The city is a weighted undirected graph with vertices and edges. The factory is at vertex . Some vertices contain machines. The -th machine is described by a triple , where is the vertex the machine is in, is the time needed to install and warm up the machine, and is the rate at which the machine produces Shimmer components.
Silco has free couriers. Each courier can bring one machine. A courier who has delivered a machine must lie low and cannot go for more machines. So Silco can deliver at most machines to the factory.
All couriers start at the factory at time . To reach a machine, a courier needs time equal to the sum of edge weights on the shortest path to the vertex containing that machine. If a machine is in vertex , delivering it takes no time, but it still requires one courier.
When a machine arrives at the factory, it first spends time units on preparation, after which it produces one component every time units. What is the minimum time needed to produce components?
Input
The first line contains three integers , , and , the number of vertices, the number of edges, and the number of couriers ().
The next lines each contain three integers , , and , meaning that an edge of weight connects vertices and (; ; ). All listed edges are distinct.
The next line contains a single integer , the number of machines in the city ().
Each of the next lines describes one machine with three integers , , and : the vertex containing the machine, its warm-up time, and the time it takes to produce one component (; ).
The last line contains a single integer , the number of components to produce ().
Output
Print a single integer, the minimum time needed to produce components.