Fence Painting
InterviewTime limit1sMemory limit1024 MB
Given painted house numbers and a distance K, list the unpainted houses within K of a painted house, merging consecutive runs as a..b.
- Level
Medium4 of 10
- Topics
- Sorting, Intervals, Implementation
- Solved
- No attempts yet
Problem
Tom Sawyer got into big trouble again, so Aunt Polly wants to send him out to paint the fence. The fences of Tom and his bad friends have all been repainted already, and some of them more than once. Now the fences of their neighbors must be painted.
The houses on the street where Tom lives stand on one side of the street and are numbered with consecutive integers starting from 1. Aunt Polly decides to have the fences repainted for every house that is at distance at most from Tom's house or from one of his friends' houses.
Input
The first line contains an integer (). The second line contains the number of already painted fences (). Each of the next lines contains the number of a house whose fence is already painted, one number per line ().
Output
Print, in increasing order, the numbers of the houses whose fences are not painted yet and that are at distance at most from a house with a painted fence. The list can be long, so compress it: instead of printing two or more consecutive house numbers separately, print the first number, two dots, and the last number on one line.