Capitals and cities

2.9

82 votes
Basic Programming, Basics of Implementation, Easy, Implementation, Sorting
Problem

Suppose we have n cities with integer coordinate on a line. First, we have to select a city to be the capital. Then in each operation, we have to choose a non-capital city and change it's coordinate by 1 (1 or +1). We have to pick the capital and do the operations exactly k time so that the sum of distances from cities to the capital is minimized. Print the index of the selected capital and the desired sum after exactly k operations. If there are multiple such choices, output the smallest index of an optimal capital. 

You are required to print the index of the selected capital and required sum after k operations. If there are multiple such choices, print the smallest index of an optimal capital.

Input format

  • First line: Two integers n and k 1n300 000
  • Second line: n integers where the ith integer that contains the coordinate of the ith city

Output format

Print two integers that represent the index of the capital and the minimized required sum respectively.

Constraints

1n300 000

0k,Ai109

Sample input #2

5 47019
19912129 5 7138912 913 200134

Sample output #2

5 27003104

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

In the first sample we should choose the first city as the capital and move the other one four times.

Note that two or more cities may coincide before or after the operations.

In the second sample it's optimal to choose the last city as the capital.

Editor Image

?