CF1214F.Employment

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Two large companies "Cecsi" and "Poca Pola" are fighting against each other for a long time. In order to overcome their competitor, "Poca Pola" started a super secret project, for which it has total nn vacancies in all of their offices. After many tests and interviews nn candidates were selected and the only thing left was their employment.

Because all candidates have the same skills, it doesn't matter where each of them will work. That is why the company decided to distribute candidates between workplaces so that the total distance between home and workplace over all candidates is minimal.

It is well known that Earth is round, so it can be described as a circle, and all mm cities on Earth can be described as points on this circle. All cities are enumerated from 11 to mm so that for each ii ( 1im11 \le i \le m - 1 ) cities with indexes ii and i+1i + 1 are neighbors and cities with indexes 11 and mm are neighbors as well. People can move only along the circle. The distance between any two cities equals to minimal number of transitions between neighboring cities you have to perform to get from one city to another. In particular, the distance between the city and itself equals 00 .

The "Poca Pola" vacancies are located at offices in cities a1,a2,,ana_1, a_2, \ldots, a_n . The candidates live in cities b1,b2,,bnb_1, b_2, \ldots, b_n . It is possible that some vacancies are located in the same cities and some candidates live in the same cities.

The "Poca Pola" managers are too busy with super secret project, so you were asked to help "Poca Pola" to distribute candidates between workplaces, so that the sum of the distance between home and workplace over all candidates is minimum possible.

输入格式

The first line contains two integers mm and nn ( 1m1091 \le m \le 10^9 , 1n2000001 \le n \le 200\,000 ) — the number of cities on Earth and the number of vacancies.

The second line contains nn integers a1,a2,a3,,ana_1, a_2, a_3, \ldots, a_n ( 1aim1 \le a_i \le m ) — the cities where vacancies are located.

The third line contains nn integers b1,b2,b3,,bnb_1, b_2, b_3, \ldots, b_n ( 1bim1 \le b_i \le m ) — the cities where the candidates live.

输出格式

The first line should contain the minimum total distance between home and workplace over all candidates.

The second line should contain nn different integers from 11 to nn . The ii -th of them should be the index of candidate that should work at ii -th workplace.

输入输出样例

  • 输入#1

    10 3
    1 5 5
    10 4 6
    

    输出#1

    3
    1 2 3 
  • 输入#2

    10 3
    1 4 8
    8 3 6
    

    输出#2

    4
    2 3 1 

说明/提示

In the first example, the distance between each candidate and his workplace equals to 11 (from 11 to 1010 , from 44 to 55 and from 66 to 55 ).

In the second example:

  • The second candidate works at first workplace, the distance between cities 33 and 11 equals to 22 .
  • The third candidate works at second workplace, the distance between cities 66 and 44 equals to 22 .
  • The first candidate works at third workplace, the distance between cities 88 and 88 equals to 00 .
首页