Bus Wireless Network Bandwidth
Time limit1sMemory limit128 MB
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.
- The bus line: how many stops there are, and how many seconds it takes to travel between each pair of adjacent stops.
- The wireless network: the total available bandwidth is 1 megabyte per second. For each seat you are given the proportion of bandwidth that the seat commands. If is the set of occupied seats, then seat receives of the bandwidth. All proportions 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 of the bandwidth and the other gets . If all three seats are occupied, the first person gets , the second , and the third .
- 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 . Then data sets follow, each in the form below.
The first line contains four integers . Here is the number of bus stops (), is the number of seats (), is the number of passengers, and () is your passenger number.
The next line contains integers giving the travel time in seconds from stop to stop . The following line contains non-negative integers giving the proportion commanded by seat .
Then lines follow, one per passenger , each with two integers: the stop where the passenger boards and the stop where the passenger gets off. Passengers are sorted by non-decreasing boarding stop .
Output
For each data set, first print Data Set x: on its own line, where 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.