#P9115. Parking Lot Revenue Calculation
Parking Lot Revenue Calculation
Parking Lot Revenue Calculation
A parking lot has \(N\) parking spaces numbered from \(1\) to \(N\). Every morning, the parking lot is empty. As each car arrives, the attendant checks if there is any available parking space. If there is at least one, the car will park in the available space with the smallest number; if there is no available space, the car will wait in a queue at the entrance. When a parking space becomes available, if there is a waiting queue, the car at the front (the one that arrived earliest) will then take that newly freed spot.
Each car is charged a fee calculated as:
\(\text{Fee} = \text{(weight of car)} \times \text{(rate of assigned parking space)}\)
The fee is independent of the duration the car stays. Given the specific rate for each parking space, the weight for each car, and the arrival and departure order for all \(M\) cars, compute the total revenue for the day.
inputFormat
The input is given in the following format:
N M r1 r2 ... rN w1 w2 ... wM event1 event2 ... event2*M
Where:
- \(N\) is the number of parking spaces.
- \(M\) is the number of cars.
- The next \(N\) lines each contain an integer \(r_i\), representing the rate for parking space \(i\).
- The following \(M\) lines each contain an integer \(w_i\), representing the weight of car \(i\).
- The final \(2M\) lines describe the sequence of events. A positive integer indicates the arrival of that car, and a negative integer indicates the departure of that car. The events are given in chronological order.
outputFormat
Output a single integer which is the total revenue generated, computed as the sum of the fees for all parked cars.
sample
2 3
2
3
200
100
300
1
2
-1
3
-2
-3
1300
</p>