3 solutions
-
-2
using namespace std; const int N = 1e5 + 5; int n, x[N], y[N]; int main() { ios::sync_with_stdio(false); cin.tie(); cout.tie(); cin >> n; for (int i = 1;i <= n;i++) { cin >> x[i]; } for (int i = 1;i <= n;i++) { cin >> y[i]; } sort (x, x + n + 1); sort (y, y + n + 1); int xmid = x[(n + 1) / 2]; int ymid = y[(n + 1) / 2]; long long ans = 0; for (int i = 1;i <= n;i++) { ans += abs(x[i] - xmid) + abs(y[i] - ymid); } cout << ans; return 0; }
Information
- ID
- 1090
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 6
- Tags
- # Submissions
- 48
- Accepted
- 14
- Uploaded By