You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
703 B

2 years ago
#include <bits/stdc++.h>
using namespace std;
const int N = 10005;
/*
petroleum
P1862
https://www.luogu.com.cn/problem/P1862
5
1 2
2 2
1 3
3 -2
3 3
6
*/
int n, a[N]; // a[0..n-1]。第i口油井的纵坐标在a[i]
int main() {
// 输入数据
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i] >> a[i]; // 横坐标说没有用的,可以直接抛弃掉
// 排序
sort(a, a + n);
// 两端对称取长短。中位数原理。
int sum = 0;
for (int i = 0, j = n - 1; i <= j; i++, j--) sum += a[j] - a[i];
cout << sum << endl;
return 0;
}