Files
python/TangDou/CSP-J/AcWingTraining/T5/P1889.cpp

24 lines
533 B
C++
Raw Normal View History

2025-08-30 18:35:01 +08:00
#include <bits/stdc++.h>
using namespace std;
const int N = 10010;
int x[N], y[N];
int n, res;
int main() {
cin >> n;
for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
sort(y, y + n);
sort(x, x + n);
for (int i = 0; i < n; i++) res += abs(y[i] - y[n / 2]); // 对与x轴的一条平等线的最短距离和
for (int i = 0; i < n; i++) x[i] -= i;
sort(x, x + n);
for (int i = 0; i < n; i++) res += abs(x[i] - x[n / 2]);
// 输出
cout << res << endl;
return 0;
}