eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

Circular Railway

Circular Railway

There are \textbf{L} stations along a circular railway, numbered \textbf{1} through \textbf{L}. Trains travel in both directions, and take \textbf{1}minute to get from a station to the neighbouring one (i.e., between \textbf{1}^st and \textbf{2}^nd, between \textbf{2}^nd and \textbf{3}^rd, ..., between \textbf{(L-1)-}^th and \textbf{L}-th and between \textbf{L}-th and \textbf{1}-st). There are \textbf{n} employee’s houses along the railway, and \textbf{n} offices, each house or office located near a railway station. You are to establish a one-to-one correspondence between houses and offices in such a way that total travel time (sum of travel times of each employee) is minimized. \InputFile The first line of the input file contains two integer numbers, \textbf{n} and \textbf{L} (\textbf{1} ≤ \textbf{n} ≤ \textbf{50000}, \textbf{2} ≤ \textbf{L} ≤ \textbf{10^9}). The second line contains \textbf{n} locations of the employee’s houses, and the third line contains \textbf{n} locations of the offices. Each location is an integer number between \textbf{1} and \textbf{L}. Some houses or offices or both can be located at the same railway station. \OutputFile Output the minimal total travel time followed by the description of the one-to-one correspondence. The description should be represented by \textbf{n} numbers (one for each employee, ordered as in the input), denoting the \textbf{1}-based index of the office assigned to the corresponding employee.
Лимит времени 1 секунда
Лимит использования памяти 64 MiB
Входные данные #1
3 15
1 2 10
11 12 13
Выходные данные #1
9
3 2 1