CF1214F.Employment
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:512MB
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 n vacancies in all of their offices. After many tests and interviews n 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 m cities on Earth can be described as points on this circle. All cities are enumerated from 1 to m so that for each i (1≤i≤m−1) cities with indexes i and i+1 are neighbors and cities with indexes 1 and m 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 0.
The "Poca Pola" vacancies are located at offices in cities a1,a2,…,an. The candidates live in cities b1,b2,…,bn. 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.
两家大型公司“Cecsi”和“Poca Pola”长期相互竞争。为了击败对手,“Poca Pola”启动了一项超级秘密项目,该项目在其所有办公地点共提供 n 个职位空缺。经过多轮测试与面试,已筛选出 n 名候选人,目前仅剩最后一步:正式聘用。
由于所有候选人的能力完全相同,因此具体安排哪位候选人到哪个办公地点工作并无区别。正因如此,该公司决定将候选人分配至各办公地点,使得所有候选人从住所到工作地点的总距离最小。
众所周知,地球是球形的,因此可将其建模为一个圆,而地球上的全部 m 座城市则可表示为该圆上的点。所有城市按 1 至 m 编号,使得对每个 i(1≤i≤m−1),编号为 i 和 i+1 的城市互为相邻城市;此外,编号为 1 和 m 的城市也互为相邻城市。人员只能沿该圆周移动。任意两座城市之间的距离定义为:从一座城市出发,经相邻城市间最少步数转移后到达另一座城市的步数。特别地,任一城市到其自身的距离为 0。
“Poca Pola”的 n 个职位空缺分别位于城市 a1,a2,…,an 的办公地点;而 n 名候选人则分别居住在城市 b1,b2,…,bn。注意,可能存在多个职位空缺位于同一城市,也可能存在多名候选人居住在同一城市。
“Poca Pola”的管理层正全力投入该超级秘密项目,因此请你协助“Poca Pola”完成候选人到各办公地点的分配,使得所有候选人从住所到工作地点的距离之和达到最小可能值。
输入格式
The first line contains two integers m and n (1≤m≤109, 1≤n≤200000) — the number of cities on Earth and the number of vacancies.
The second line contains n integers a1,a2,a3,…,an (1≤ai≤m) — the cities where vacancies are located.
The third line contains n integers b1,b2,b3,…,bn (1≤bi≤m) — the cities where the candidates live.
第一行包含两个整数 m 和 n(1≤m≤109,1≤n≤200000)—— 分别表示地球上的城市总数和职位空缺数量。
第二行包含 n 个整数 a1,a2,a3,…,an(1≤ai≤m)—— 表示各职位空缺所在的城市。
第三行包含 n 个整数 b1,b2,b3,…,bn(1≤bi≤m)—— 表示各位候选人所居住的城市。
输出格式
The first line should contain the minimum total distance between home and workplace over all candidates.
The second line should contain n different integers from 1 to n. The i-th of them should be the index of candidate that should work at i-th workplace.
第一行应包含所有候选人在家庭与工作地点之间的最小总距离。
第二行应包含 n 个互不相同的、取值范围为 1 到 n 的整数。其中第 i 个整数表示应被分配到第 i 个工作地点的候选人的编号。
输入输出样例
输入#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 1 (from 1 to 10, from 4 to 5 and from 6 to 5).
In the second example:
- The second candidate works at first workplace, the distance between cities 3 and 1 equals to 2.
- The third candidate works at second workplace, the distance between cities 6 and 4 equals to 2.
- The first candidate works at third workplace, the distance between cities 8 and 8 equals to 0.
在第一个例子中,每位候选人与其工作地点之间的距离均为 1(从城市 1 到城市 10,从城市 4 到城市 5,以及从城市 6 到城市 5)。
在第二个例子中:
- 第二位候选人工作于第一个工作地点,城市 3 与城市 1 之间的距离为 2;
- 第三位候选人工作于第二个工作地点,城市 6 与城市 4 之间的距离为 2;
- 第一位候选人工作于第三个工作地点,城市 8 与城市 8 之间的距离为 0。
输入解题思路,AI测评打分。不知道怎么写?