Under construction

Still being built. Things may change

Black Holes and Asteroids

Interview

Time limit1sMemory limit1024 MB

Summary
Given black hole and asteroid positions, find the smallest integer P so that every asteroid is within P/w of some black hole.
Level

Medium4 of 10

Topics
Sorting, Binary search, Greedy
Solved
No attempts yet

Problem

There are NN black holes and MM asteroids on a number line in the current simulation universe. All NN black holes have the same pulling force PP.

If black hole ii is at position bib_i, and asteroid jj is at position aja_j with mass wjw_j, then black hole ii pulls in asteroid jj when ∣bi−aj∣≤Pwj\vert b_i - a_j \vert \leq \frac{P}{w_j}. (1≤i≤N; 1≤j≤M)(1 \le i \le N;\ 1 \le j \le M)

One black hole can pull in several asteroids. When several different black holes can pull in the same asteroid, the leftmost black hole pulls it in.

Find the minimum integer PP that lets the black holes pull in every asteroid in the simulation universe.

Input

The first line contains the number of black holes NN and the number of asteroids MM, separated by a space. (1≤N,M≤200 000)(1 \le N, M \le 200\,000)

The second line contains NN integers b1,b2,⋯ ,bNb_1, b_2, \cdots, b_N, separated by spaces. (−1 000 000≤bi≤1 000 000)(-1\,000\,000 \le b_i \le 1\,000\,000)

From the third line onward, the next MM lines describe the asteroids. The jj-th of these lines contains two integers aja_j and wjw_j, separated by a space. (−1 000 000≤aj≤1 000 000;1≤wj≤100)(-1\,000\,000 \le a_j \le 1\,000\,000; 1 \le w_j \le 100)

Each position holds either a single black hole or a single asteroid.

Output

Print the minimum integer PP that lets the black holes pull in every asteroid.

Hint

∣x∣|x| is the absolute value of xx. If x≥0x \ge 0, then ∣x∣=x|x| = x, and if x<0x < 0, then ∣x∣=−x|x| = -x.

Examples1

  1. Example 1

    Input
    2 3
    1 5
    2 3
    7 1
    4 2
    
    Expected output
    3