Under construction

Still being built. Things may change

Stargazing Trip

Time limit2sMemory limit1024 MB

Summary
Split M stars, kept in observation order, into N nonempty consecutive groups to maximize the sum of each group's Manhattan diameter.
Level

Medium6 of 10

Topics
Dynamic programming, Geometry
Solved
No attempts yet

Problem

Astronomer Suyeon observed a total of MM stars over NN days and recorded each star's coordinates in the order she observed them. If you treat the night sky as a two-dimensional coordinate plane, each star is a point on that plane.

The representative value RR of the stars Suyeon observed on a given day is the distance between the two farthest stars among those observed that day. If the two stars have coordinates (a,b)(a,b) and (c,d)(c,d), their distance is ∣a−c∣+∣b−d∣|a-c|+|b-d|. For example, if Suyeon observed 4 stars at (1,3)(1,3), (6,−3)(6,-3), (−1,5)(-1,5), (5,4)(5,4) in that order, the representative value of that day is R=∣6−(−1)∣+∣−3−5∣=15R=|6-(-1)|+|-3-5|=15. If only one star was observed on a day, its representative value is 0.

Suyeon remembers that she observed at least one star every day, but she forgot which star she observed on which day. She wants to split the stars into days while keeping the observation order, so that the sum of the representative values over the NN days is as large as possible, based on the fact that each day has at least one star.

For example, for 3 days and 5 stars [p1,p2,…,p5][p_1,p_2,\dots,p_5], the split [p1,p2][p_1,p_2], [p3][p_3], [p4,p5][p_4,p_5] is valid, but [p1,p3][p_1,p_3], [p2][p_2], [p4,p5][p_4,p_5] and [p1,p2][p_1,p_2], [p3,p4,p5][p_3,p_4,p_5] are not.

Input

The first line contains NN and MM, the number of days and the number of stars, separated by a space. (1≤N≤M≤3000)(1\leq N\leq M\leq 3000)

Each of the next MM lines contains the xx and yy coordinates of a star, separated by a space. (−109≤x,y≤109)\left(-10^{9}\leq x, y\leq 10^{9}\right)

All values in the input are integers.

Output

Print the maximum possible value of ∑i=1NRi\sum_{i=1}^{N}R_i when the stars are split into days as described above.

Examples2

  1. Example 1

    Input
    2 3
    1 2
    3 4
    -1 4
    
    Expected output
    4
    
  2. Example 2

    Input
    3 7
    3 2
    -1 0
    5 4
    0 0
    4 8
    9 9
    5 2
    
    Expected output
    33