Under construction

Still being built. Things may change

Like a Bridge over Troubled Freeways

Interview

Time limit1sMemory limit1024 MB

Summary
Place c crossings on the x-axis so the average of each animal's walk (|y| plus horizontal distance to the nearest crossing) is minimized.
Level

Medium5 of 10

Topics
Dynamic programming, Sorting, Prefix sum
Solved
No attempts yet

Problem

One of the legacies of P-22's story is that California is building more wildlife crossings over and under freeways. P-22 survived his long journey, in part thanks to your solution to the previous problem, but many other mountain lions do not. The idea is that animals will learn to use these crossings instead of running across the freeway, which reduces deaths among them and the risk to humans from traffic accidents. The first wildlife crossing directly inspired by P-22, the Wallis Annenberg Crossing, began construction in April 2022.

Here, your goal is to decide where to build several wildlife crossings so that animals walk as little as possible. The budget of Caltrans and CDFW determines how many crossings you can build. You should choose their locations to minimize the average distance animals walk to their closest crossings. Each animal i lives at coordinates (xi,yi)(x_i, y_i). The freeway is modeled as the infinite x-axis, going from (−∞,0)(-\infty, 0) to (+∞,0)(+\infty, 0). You can choose cc locations on the freeway for your crossings. An animal that needs to cross the freeway first walks in a straight line to the freeway, then walks along the freeway to the closest crossing you have built.

Input

The first line contains KK (1≤K≤1001 \le K \le 100), the number of data sets. Each data set begins with a line containing two integers cc and nn, where 1≤c≤401 \le c \le 40 is the number of crossings you can build and 1≤n≤1001 \le n \le 100 is the number of animals. The next nn lines each give the location xix_i, yiy_i of an animal as a floating point number between −1000000.0-1000000.0 and 1000000.01000000.0.

Output

For each data set, print "Data Set x:" on a line by itself, where x is the data set number. Then print the minimum average distance from all animals to their respective closest crossings that you can achieve by building cc crossings. Print a blank line after each data set.

Examples1

  1. Example 1

    Input
    1
    3 5
    0 -2.5
    17 -5
    1 -6
    42 0.2
    3 3
    
    Expected output
    Data Set 1:
    19.70