Stargazing Trip
Time limit2sMemory limit1024 MB
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 stars over 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 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 and , their distance is . For example, if Suyeon observed 4 stars at , , , in that order, the representative value of that day is . 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 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 , the split , , is valid, but , , and , are not.
Input
The first line contains and , the number of days and the number of stars, separated by a space.
Each of the next lines contains the and coordinates of a star, separated by a space.
All values in the input are integers.
Output
Print the maximum possible value of when the stars are split into days as described above.