问题 H: Matches

内存限制:128 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:23 通过:23

题目描述

Walk Alone has two rows of matches, each of which contains n matches. He defines the distance between them as d=∑ni=1∣ai−bi∣, where ai and bi represent the height of the i-th match in the first row and the second row, respectively. Walk Alone wants to beautify the matches by shortening the distance, and you are asked to find out the minimum distance after performing at most one swap within one row. Note that the height can be negative.

输入格式

The first line contains one integer n (1≤n≤10^6), denoting the number of matches in each row.
The second and the third line both contains nnn integers, representing the height of matches in the first row and the second row, respectively. All of these numbers satisfy ∣ai∣,∣bi∣≤10^9.

输出格式

Print one line containing a single integer, the minimum distance you can get.

输入样例 复制

3
1 2 3
3 2 1

输出样例 复制

0

分类标签