Meet at a point
unknown
c_cpp
a year ago
597 B
6
Indexable
Never
#include <bits/stdc++.h> using namespace std; int main() { int t, n, i, j; cin >> t; while (t--) { int n; cin >> n; vector<int> x(n), y(n); for (int i = 0; i < n; i++) { cin >> x[i] >> y[i]; } sort(x.begin(), x.end()); sort(y.begin(), y.end()); long long int ans = 0; int j = n / 2; for (int i = 0; i < n; i++) { ans += abs(x[i] - x[j]); ans += abs(y[i] - y[j]); } cout << ans << "\n"; } }