Under construction

Still being built. Things may change

Ramen Shop Seating

Time limit8sMemory limit512 MB

Summary
Simulate a ramen shop with N counters of fixed seats where arriving groups pick the best free block under a preference rule and may leave if they wait too long; report average customer satisfaction.
Level

Hard8 of 10

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

Problem

Ron runs a ramen shop.

He recently noticed that customers wait a long time at lunch because the shop runs out of seats. A customer who waits long is less satisfied, and some customers give up and leave. He decided to add seats, and he asked you to write a simulator of customer behavior so he can judge how many seats are enough.

Customers arrive in groups. Each group is described by four values.

  • TiT_i: the time the group arrives at the shop
  • PiP_i: the number of customers in the group
  • WiW_i: how long the group can wait for seats
  • EiE_i: how long the group spends eating

Group ii arrives at time TiT_i with PiP_i customers together. If PiP_i successive empty seats are available at one counter at that time, the group sits down at once. Otherwise the group waits until such seats become free. If the group cannot sit down at a time that is within WiW_i of its arrival (the endpoint counts) and strictly before the closing time, the group gives up waiting and leaves. Also, when an earlier group is waiting, a later group cannot take seats until every earlier group has either sat down or left.

The shop has counters numbered 11 to NN, and counter ii has CiC_i seats in one row. A group prefers seats far away from other customers. Precisely, the group chooses seats by the criteria below. Let SLS_L be the number of successive empty seats to the left of the group after it sits down, and SRS_R the number to the right. If there is no other customer on the left side, SLS_L counts as infinity, and if there is no other customer on the right side, SRS_R counts as infinity.

  1. Choose seats maximizing min⁡(SL,SR)\min(S_L, S_R).
  2. If several choices remain, choose seats maximizing max⁡(SL,SR)\max(S_L, S_R).
  3. If several choices still remain, choose the counter with the smallest number.
  4. If several choices still remain, choose the leftmost seats.

When several groups finish eating and leave at the same time and some group is waiting, assign seats to the waiting group after all the finishing groups have left.

The satisfaction of one customer is defined as follows.

  • A customer of a group that leaves without eating has satisfaction −1-1.
  • Otherwise the satisfaction is (Wi−ti)/Wi(W_i - t_i)/W_i, where tit_i is the time group ii actually waited. This value is between 00 and 11 inclusive.

Compute the average satisfaction over all customers.

Input

The input consists of multiple datasets. Each dataset has the following format.

N M T
C_1 C_2 ... C_N
T_1 P_1 W_1 E_1
T_2 P_2 W_2 E_2
...
T_M P_M W_M E_M

NN is the number of counters, MM is the number of groups, and TT is the closing time. The shop always opens at time 00. Every input value is an integer.

1≤N≤1001 \le N \le 100, 1≤M≤100001 \le M \le 10000, 1≤T≤1091 \le T \le 10^9, 1≤Ci≤1001 \le C_i \le 100, 0≤T1<T2<⋯<TM<T0 \le T_1 < T_2 < \dots < T_M < T, 1≤Pi≤max⁡jCj1 \le P_i \le \max_j C_j, 1≤Wi≤1091 \le W_i \le 10^9, and 1≤Ei≤1091 \le E_i \le 10^9.

A line holding three zeros ends the input. That line is not a dataset.

Output

For each dataset, print the average satisfaction over all customers on one line. Round the value to 1010 digits after the decimal point and print exactly 1010 digits.

Examples2

  1. Example 1

    Input
    1 4 100
    7
    10 1 50 50
    15 2 50 50
    25 1 50 50
    35 3 50 50
    1 2 100
    5
    30 3 20 50
    40 4 40 50
    1 2 100
    5
    49 3 20 50
    60 4 50 30
    1 2 100
    5
    50 3 20 50
    60 4 50 30
    2 3 100
    4 2
    10 4 20 20
    30 2 20 20
    40 4 20 20
    0 0 0
    
    Expected output
    0.7428571429
    0.4285714286
    0.5542857143
    -0.1428571429
    0.8000000000
    
  2. Example 2

    Input
    1 1 10
    3
    0 3 5 5
    2 2 50
    1 1
    0 1 10 5
    1 1 10 5
    0 0 0
    
    Expected output
    1.0000000000
    1.0000000000