Company: Consultadd_8june
Difficulty: medium
A logistics company maintains service hubs positioned along a straight highway. You are given: a sorted array positions[] representing hub locations, an integer k , and a target location x . Find the k hubs closest to the target location. Rules: A hub with smaller distance to x is considered closer. If two hubs are equally distant, choose the hub with smaller position value. Return the selected hubs in sorted order. Input Format First line contains integer n Second line contains n sorted integers Third line contains integer k Fourth line contains integer x Output Format Print k integers in sorted order. Constraints 1 <= k <= n <= 10^4 -10^4 <= positions[i], x <= 10^4 Example 1 Input 6 1 1 2 3 4 5 4 -1 Output 1 1 2 3 Example 2 Input 5 1 2 3 4 5 4 3 Output 1 2 3 4