Bus Wireless Network Bandwidth

Time limit1sMemory limit128 MB

Summary
Simulate passengers boarding and leaving a bus, assigning each the highest-proportion free seat, and compute the bandwidth share obtained by a specified passenger.
Level

Medium6 of 10

Topics
Simulation, Sorting, Implementation, Math
Solved
No attempts yet

Problem

One amenity being added to buses and trains to attract or retain riders is a wireless network. Commuters can get work done while traveling, or browse the Internet just like at home. Of course, the more riders use the service, the less bandwidth is left for any one person, making it a little less attractive. Wouldn't it be nice if, before downloading a big file, you knew who boards and leaves the bus and when, so you could compute exactly how much bandwidth you will get during your ride?

Write a program to compute this. You are given the following data.

  1. The bus line: how many stops there are, and how many seconds it takes to travel between each pair of adjacent stops.
  2. The wireless network: the total available bandwidth is 1 megabyte per second. For each seat ii you are given the proportion aia_i of bandwidth that the seat commands. If SS is the set of occupied seats, then seat i∈Si \in S receives ai∑j∈Saj\dfrac{a_i}{\sum_{j \in S} a_j} of the bandwidth. All proportions aia_i for different seats are distinct. For example, suppose there are three seats with proportions 3, 2, 1. If only the first two seats are occupied, the person in the first seat gets 3/5=60%3/5 = 60\% of the bandwidth and the other gets 2/5=40%2/5 = 40\%. If all three seats are occupied, the first person gets 3/6=50%3/6 = 50\%, the second 2/6≈33.333%2/6 \approx 33.333\%, and the third 1/6≈16.667%1/6 \approx 16.667\%.
  3. The passengers: at which stops each passenger (including you) boards and gets off. At any stop, everyone getting off leaves before anyone boarding gets on. When boarding, a passenger always takes the best available seat (the highest proportion) and never switches seats later, even if a better seat becomes free. If the bus is full, the passenger cannot board (this may include you). If several passengers board at the same stop, they try in the order listed in the input.

Input

The first line contains the number of data sets KK. Then KK data sets follow, each in the form below.

The first line contains four integers n,m,p,yn, m, p, y. Here nn is the number of bus stops (2≤n≤1002 \le n \le 100), mm is the number of seats (1≤m≤1001 \le m \le 100), pp is the number of passengers, and yy (1≤y≤p1 \le y \le p) is your passenger number.

The next line contains n−1n-1 integers giving the travel time in seconds from stop ii to stop i+1i+1. The following line contains mm non-negative integers giving the proportion aia_i commanded by seat ii.

Then pp lines follow, one per passenger jj, each with two integers: the stop sjs_j where the passenger boards and the stop tj>sjt_j > s_j where the passenger gets off. Passengers are sorted by non-decreasing boarding stop sjs_j.

Output

For each data set, first print Data Set x: on its own line, where xx is the data set number. On the next line, print the total bandwidth in megabytes that you obtained, rounded to two decimals. Separate consecutive data sets with a single blank line.

Examples1

  1. Example 1

    Input
    2
    2 2 3 3
    600
    2 1
    1 2
    1 2
    1 2
    6 3 6 2
    231 165 198 132 132
    1 2 3
    1 2
    1 5
    1 3
    3 5
    4 6
    4 6
    
    Expected output
    Data Set 1:
    0.00
    
    Data Set 2:
    310.20