Connection Optimization

4

4 votes
Implementation, Basic Programming, Hard, Basics of Implementation
Problem

There are N houses in a city. Each house is numbered from 1 to N. This city is a 2D cartesian plane. The location of each house is denoted by the coordinate (x,y). The government wants to establish electric poles to which these houses can be connected. Each house must be connected to exactly one electric pole. The cost of placing a single pole is denoted by the integer Z. You can connect each pole to at most K distinct houses. To minimize the overutilization of resources, the number of poles is restricted to a specific number that is denoted by L.
The overall cost of this operation is given by Z×P+D, where D is the sum of the Euclidean distance of all the houses to the respective poles they are connected to and P is the number of poles used. Your task is to minimize the cost.

Input format

  • First line: Four space-separated integers NZ, K, and L 
  • Next N lines: Location of houses denoted by (x,y)


Output format

  • First line: Integer P denoting the number of poles used
  • Next P lines:
    • Location of each pole denoted as a 2D-integer coordinate,
    • Number of houses that are connected to the respective electric pole
    • Numbers of each house that are connected 

Constraints
1N105
107x[i],y[i]107
1Z108
1KN
(N+K1)/KLN

Scoring
The score is calculated by the formula Z×P+D and you are required to minimize this score. If any of these constraints is violated, your answer is wrong. The coordinate of the poles should also lie in the range 107 to 107 .

Test Generation
The test files contain three types of test cases - Points randomly generated across the whole plane (not necessarily uniform), All points in a straight line, All points in the border of a rectangle and the ratio is 60%, 20%, 20% of all the test cases (approximately).

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

The cost for the sample output is given by 2×50+3=103

Editor Image

?