Dividing the Land

Time limit1sMemory limit128 MB

Summary
For each test case, split N cities with K-1 evenly spaced vertical or horizontal cuts, avoid cuts through cities, and print the minimum average |count - N/K| as a reduced fraction.
Level

Medium5 of 10

Topics
Sorting, Math, Implementation, Geometry
Solved
No attempts yet

Problem

When Kim Sang-geun, emperor of the Changyoung Empire, passed away, the question of how to split his empire among his children remained. The empire is a rectangle that contains NN cities.

The empire must be split into exactly KK pieces, using one of only two methods:

  • Vertical cuts: draw K−1K-1 equally spaced vertical lines to split the empire into KK vertical strips of equal width.
  • Horizontal cuts: draw K−1K-1 equally spaced horizontal lines to split the empire into KK horizontal strips of equal height.

Because every piece must have the same size, the cut positions are fixed for each method. The border of the empire is the smallest axis-aligned rectangle that contains all cities. A cutting line need not have integer coordinates, but it must not pass through a city: if one of the equally spaced lines of a method would land exactly on a city, that method cannot be used.

Each child receives one of the KK pieces together with the cities inside it. The fair target is N/KN/K, and a child who receives a piece holding cc cities has an unfairness score of ∣c−N/K∣|c - N/K|.

Choose the better of the two methods so that the average unfairness score over all children is minimized, and report that minimum as an irreducible fraction.

For example, with 66 cities and 33 children the target is 6/3=26/3 = 2. If the three pieces hold 2,3,12, 3, 1 cities, the unfairness scores are 0,1,10, 1, 1 with an average of 2/32/3. If instead the cities can be split evenly into 2,2,22, 2, 2, the average becomes 00.

Input

The input consists of several test cases. The first line of each test case contains the number of cities NN and the number of children KK. (1≤K≤10, K≤N≤100,000)(1 \le K \le 10,\ K \le N \le 100{,}000)

Each of the next NN lines contains the integer coordinates xx and yy of a city. (0≤x,y≤100,000)(0 \le x, y \le 100{,}000) Because the coordinates are rounded to the nearest integers, several cities may share the same coordinates.

The last line of the input contains two zeros and must not be processed.

In every test case at least one of the two methods can always be used.

Output

For each test case, print the test case number and the minimum average unfairness score. Write the average as an irreducible fraction A/B, using B=1B = 1 when the value is an integer. Each line has the format number. A/B.

Examples1

  1. Example 1

    Input
    6 3
    0 4
    1 3
    2 3
    3 1
    4 4
    5 0
    4 3
    0 0
    0 1
    1 1
    1 0
    0 0
    
    Expected output
    1. 0/1
    2. 8/9