Under construction

Still being built. Things may change

Heritage

Time limit0.3sMemory limit64 MB

Summary
Divide a region under a polygonal line into parcels whose areas match given ratios, choosing vertical cuts that minimize the total fence length.
Level

Hard8 of 10

Topics
Dynamic programming, Geometry, Binary search, Prefix sum
Solved
No attempts yet

Problem

The old Count D owns a piece of land that he wants to divide among his nn sons.

The land lies above the OxOx axis. Its lower boundary is the horizontal segment [AB][AB] on the OxOx axis, its left and right boundaries are the vertical segments [AP1][AP_1] and [BPm][BP_m], and its upper boundary is the polygonal line P1P2…PmP_1P_2\dots P_m, which lies entirely above the OxOx axis.

The Count builds n−1n-1 vertical fences. Each fence joins the base segment [AB][AB] to the polygonal line, so a fence placed at coordinate xx has length equal to the height of the polygonal line at xx. The fences split the land into nn parcels, ordered from left to right.

The parcelling must satisfy both of the following conditions:

  1. The parcels can be assigned to the sons so that each son's parcel has an area directly proportional to his age.
  2. Among all parcellings that satisfy condition 1, the total length of the fences is as small as possible.

Given the mm points P1,…,PmP_1, \dots, P_m and the ages of the nn sons, compute the minimum possible total fence length.

Input

The first line contains two integers nn and mm.

The second line contains nn integers v1,v2,…,vnv_1, v_2, \dots, v_n — the ages of the sons.

Each of the next mm lines contains two integers xix_i and yiy_i — the coordinates of point PiP_i.

Output

Print a single real number: the minimum possible total length of the n−1n-1 fences, rounded to exactly 6 decimal places.

Constraints

  • 1≤n≤81 \le n \le 8
  • 1≤m≤5001 \le m \le 500
  • 1≤vi≤501 \le v_i \le 50
  • 0≤x1<x2<⋯<xm≤320000 \le x_1 < x_2 < \dots < x_m \le 32000
  • 1≤y1,y2,…,ym≤320001 \le y_1, y_2, \dots, y_m \le 32000
  • Fence widths are negligible.
  • Use double-precision floating point for the computation.

Hint

In the sample (the first example, n=2n = 2) only one fence is needed.

Placing the fence at x=10x = 10, where the polygonal line has height 11, gives a total fence length of 1.0000001.000000. The son aged 44 takes the left parcel (area 1616) and the son aged 22 takes the right parcel (area 88); both areas are proportional to the ages.

If the fence were placed instead at x≈6.54984x \approx 6.54984 (length ≈2.51661\approx 2.51661), the son aged 22 would take the left parcel and the son aged 44 the right one. That split still satisfies the area-proportionality condition, but its fence is longer, so it is not optimal. Every other position fails the area-proportionality condition.

Examples3

  1. Example 1

    Input
    2 4
    4 2
    2 1
    8 3
    10 1
    14 3
    
    Expected output
    1.000000
    
  2. Example 2

    Input
    1 3
    7
    0 5
    6 2
    12 8
    
    Expected output
    0.000000
    
  3. Example 3

    Input
    2 2
    1 1
    0 4
    10 4
    
    Expected output
    4.000000