Under construction

Still being built. Things may change

Dormitory Parcel Delivery

Time limit1sMemory limit1024 MB

Summary
Find the minimum time to start at the storage room, deliver every parcel, and return, when carried weight slows the walking speed to 1/(1+W).
Level

Hard9 of 10

Topics
Dynamic programming, Divide and conquer, Sorting
Solved
No attempts yet

Problem

A dormitory of the Korea Science Academy has an entrance and 2N+12N + 1 rooms arranged in a straight line. The ii-th room from the left is room ii, and the entrance is to the left of room 11. The distance between the entrance and room ii is xix_i meters. Room N+1N+1 is used as the parcel storage room.

Yesung has accumulated too many demerit points, so he has to deliver the parcels in the storage room. MM parcels are kept in the storage room, and the jj-th parcel must be delivered to room pjp_j and weighs wjw_j. His goal is to start from the storage room, deliver every parcel, and return to the storage room. Taking a parcel out of the storage room or putting it at its destination takes no time.

Yesung can carry any number of parcels at once with no limit. He does not have to take all the parcels at the start, and he can come back to the storage room along the way to fetch some of them. He may choose the order of deliveries freely, but he cannot leave a parcel temporarily at a place other than its destination. When Yesung carries no parcels, he moves at 1 meter per second. If the total weight of the parcels he carries is WW, his speed drops to 11+W\cfrac{1}{1 + W} meters per second.

Yesung is busy proving P=NP, so find the minimum number of seconds needed to reach the goal.

Input

The first line contains two integers NN and MM, separated by a space.

The second line contains 2N+12N + 1 integers x1,x2,⋯ ,x2N+1x_1, x_2, \cdots, x_{2N +1}, separated by spaces.

From the third line onward, the next MM lines describe the parcels. The jj-th of these lines contains two integers pjp_j and wjw_j, separated by a space.

Output

Print the answer to the problem. Under the given conditions, the answer is guaranteed to be an integer.

Constraints

  • 1≤N,M,wj≤1051 \leq N, M, w_j \leq 10^5
  • 1≤x1<x2<⋯<x2N+1≤3×1051 \leq x_1 < x_2 < \cdots < x_{2N+1} \leq 3 \times 10^5
  • 1≤pj≤2N+11 \leq p_j \leq 2N+1

Examples1

  1. Example 1

    Input
    3 5
    3 4 5 6 9 10 15
    5 10
    6 17
    4 14
    1 9
    6 9
    
    Expected output
    175