fork(1) download
  1. #include<bits/stdc++.h>
  2. #include<fstream>
  3. using namespace std;
  4. ifstream fin("VNOICUP.INP");
  5. ofstream fout("VNOICUP.OUT");
  6. #define sz(a) (int)a.size()
  7. #define ll long long
  8. #define pb push_back
  9. #define forr(i, a, b) for(int i = a; i < b; i++)
  10. #define dorr(i, a, b) for(int i = a; i >= b; i--)
  11. #define ld long double
  12. #define vt vector
  13. #include<fstream>
  14. #define fi first
  15. #define se second
  16. #define pll pair<ll, ll>
  17. #define pii pair<int, int>
  18. #define mp make_pair
  19. const ld PI = 3.14159265359;
  20. using u128 = __uint128_t;
  21. //const int x[4] = {1, -1, 0, 0};
  22. //const int y[4] = {0, 0, 1, -1};
  23. const ll mod = 1e9 + 7;
  24. const int mxn = 1e5 + 5, mxq = 2e5 + 5, sq = 400, mxv = 15 * 10, pr = 31;
  25. const int base = (1 << 18);
  26. const ll inf = 2e9, neg = -69420, add = 1e9;
  27. int n;
  28. signed main(){
  29. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  30. cin >> n;
  31. vt<ll>a(n), b(n);
  32. for(int i = 0; i < n; i++){
  33. ll x, y; cin >> x >> y;
  34. a[i] = (x + y); b[i] = (x - y);
  35. }
  36. sort(a.begin(), a.end()); sort(b.begin(), b.end());
  37. ll ma = a[sz(a) / 2], mb = b[sz(b) / 2];
  38. ll res = 1e18;
  39. for(auto [pa, pb]: {mp(ma, mb), mp(ma - 1, mb), mp(ma + 1, mb), mp(ma, mb - 1), mp(ma, mb + 1)}){
  40. if((pa + pb) & 1)continue;
  41. ll ans = 0;
  42. for(int i = 0; i < sz(a); i++){
  43. //cout << a[i] << " ";
  44. ans += abs(a[i] - pa);
  45. }
  46. forr(i, 0, sz(b)){
  47. // cout << b[i] << " ";
  48. ans += abs(b[i] - pb);
  49. }
  50. res = min(res, ans);
  51. }
  52.  
  53. assert(res % 2 == 0);
  54. cout << res / 2;
  55. }
Runtime error #stdin #stdout 0.01s 5500KB
stdin
Standard input is empty
stdout
Standard output is empty