Section: 3, Score: 33, Time limit per test: 30 seconds, Memory limit per test: 512MB, Input: stdin, Output: stdout
Krit is a capacity planner at Agoda who frequently faces the following questions: What is the minimum time required to achieve a particular capacity for a given set of servers and an application? To answer this question, Krit must consider the fact that servers are interconnected through a bidirectional network, with each connection between two servers having a latency that is consistent in both directions.
Moreover, Krit must consider the warmup time required for each server. The warmup time is the period required for the application to launch on a server, and the server begins serving requests at maximum capacity only after the warmup period has ended.
The network contains
Given the network topology, the warmup time for each server, and the capacity of each server, Krit requires a program that utilizes this information to determine the minimum time required to reach a specific capacity for a given set of servers and an application.
The first line contains two space-separated integers
The next
The next line contains
The next line contains
The next line contains an integer
The next
For each query print the minimum time (in milliseconds) required to reach at least capacity -1
.
3 2
1 2 100
2 3 100
20 30 40
1000 1000 1000
3
700
1500
3300
20
130
-1
The server labeled as 1 can start serving in just 20ms and has the capacity to handle up to 700 requests per millisecond. In the second test case, both server 1 and server 2 have equivalent capacity, but server 2 will require 130ms to reach its maximum capacity. This is due to the time taken to receive the application from server 1 (100ms) and warm up (30ms). Server 1, on the other hand, can begin serving immediately after 20ms.
When all three servers are combined, their maximum capacity is 3000 requests per millisecond. Therefore, it is impossible for them to achieve a throughput of 3300.
5 7
1 2 9
1 4 5
1 5 7
2 3 8
2 5 3
3 4 10
4 5 8
1 2 8 5 7
9 2 5 6 4
7
17
10
1
3
19
25
4
11
10
1
1
14
23
1