450. Ramen Shop

Time limit per test: 0.25 second(s)
Memory limit: 262144 kilobytes
input: standard
output: standard



Ron is a master of a ramen shop.

Recently, he has noticed some customers wait for a long time. This has been caused by lack of seats during lunch time. Customers loses their satisfaction if they wait for a long time, and some of them will even give up waiting and go away. For this reason, he has decided to increase seats in his shop. To determine how many seats are appropriate, he has asked you, an excellent programmer, to write a simulator of customer behavior.

Customers come to his shop in groups, each of which is associated with the following four parameters:

The i-th group comes to the shop with Pi customers together at the time Ti. If Pi successive seats are available at that time, the group takes their seats immediately. Otherwise, they wait for such seats being available. When the group fails to take their seats within the time Wi (inclusive) from their coming and strictly before the closing time, they give up waiting and go away. In addition, if there are other groups waiting, the new group cannot take their seats until the earlier groups are taking seats or going away.

The shop has N counters numbered uniquely from 1 to N. The i-th counter has Ci seats. A group cannot spread over multiple counters. The group prefers "seats with a greater distance to the nearest group." Precisely, the group takes their seats according to the criteria listed below. For each block of seats of appropriate size within each counter, values SL and SR are calculated. Here, SL denotes the number of successive empty seats on the left side of the group after their seating, and SR the number on the right side. SL and SR are considered to be infinity if there are no other customers on the left side and on the right side respectively. Note that these numbers don't take into account people in other counters.
  • Prefers seats maximizing min { SL, SR }.
  • If there are multiple alternatives meeting the first criterion, prefers seats maximizing max { SL, SR }.
  • If there are still multiple alternatives, prefers the counter of the smallest number.
  • If there are still multiple alternatives, prefers the leftmost seats.

    When multiple groups are leaving the shop at the same time and some other group is waiting for available seats, seat assignment for the waiting group should be made after all the finished groups leave the shop. If a customer starts eating, he is allowed to finish even after the shop closes.

    Your task is to calculate the average satisfaction over customers. The satisfaction of a customer in the i-th group is given as follows:

    Input
    The input has the following format:

    N M T

    C1 C2... CN

    T1 P1 W1 E1

    T2 P2 W2 E2

    ...

    TM PM WM EM

    N indicates the number of counters, M indicates the number of groups and T indicates the closing time. The shop always opens at the time 0. All input values are integers.

    You can assume that 1 ≤ N ≤ 100, 1 ≤ M ≤ 10000, 1 ≤ T ≤ 109, 1 ≤ Ci ≤ 100, 0 ≤ T1 < T2 <... < TM < T, 1 ≤ Pimax{Ci}, 1 ≤ Wi ≤ 109 and 1 ≤ Ei ≤ 109.

    Output
    Output the average satisfaction over all customers in a line. The output value may be printed with an arbitrary number of fractional digits, but may not contain an absolute error greater than 10-9.

    Example(s)
    sample input
    sample output
    1 4 100
    7
    10 1 50 50
    15 2 50 50
    25 1 50 50
    35 3 50 50
    
    0.7428571428571429
    

    sample input
    sample output
    1 2 100
    5
    30 3 20 50
    40 4 40 50
    
    0.4285714285714285
    

    sample input
    sample output
    1 2 100
    5
    49 3 20 50
    60 4 50 30
    
    0.5542857142857143
    

    sample input
    sample output
    1 2 100
    5
    50 3 20 50
    60 4 50 30
    
    -0.1428571428571428
    

    sample input
    sample output
    2 3 100
    4 2
    10 4 20 20
    30 2 20 20
    40 4 20 20
    
    0.8000000000000000
    




  • Online Contester Team © 2002 - 2010. All rights reserved.