Language: C++

è³ÅACµ½ÌÉAOJ¾ÆWAÉÈÁÄßµ¢
#include<iostream>
#include<cstdlib>
#include<queue>
#include<cstdio>
#include<vector>
#include<cassert>
#include<cstdlib>
#include<algorithm>
#include<ctime>
#include<map>
#include<climits>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;

ll myabs(ll a,ll b){
  return max(a,b)-min(a,b);
}

void precalc(vector<pair<ll,ll> > &in,vector<pli> & ret,map<ll,int> & Y){
  int n = in.size();
  ll mini = LONG_LONG_MAX;
  //yÀWÌ³kAÅ¬lßÄ¨­

  map<ll,int> M;
  rep(i,(int)in.size()){
    M[in[i].first]++;
    mini = min(mini,in[i].first);
  }
  //úlðvZ
  ll pos = 2*M[mini],neg = 2*(n-M[mini]),prev = mini;
  ll cur=0;
  rep(i,(int)in.size())cur += 2*((ll)in[i].first-(ll)mini);
  ret.push_back(make_pair(cur,mini));

  //
  int index = 0;
  Y[mini] = index++;
  map<ll,int>::iterator itr = M.begin();itr++;
  while(itr != M.end()){
    int fir = (*itr).first,sec=(*itr).second;
    ll diff = fir - prev;
    Y[fir] = index++;
    cur = cur + pos * diff - neg * diff;
    //    cout << cur << " " << pos/2 <<" " << neg/2 <<" " << diff << endl;
    ret.push_back(make_pair(cur,fir));
    neg-=sec*2;
    pos+=sec*2;
    prev = fir;
    itr++;
  }
}

void bf(vector<pair<ll,ll> > &in){
  vector<ll> x,y;
  rep(i,in.size()){
    swap(in[i].second,in[i].first);
    x.push_back(in[i].second);
    y.push_back(in[i].first);
  }
  sort(x.begin(),x.end());x.erase(unique(x.begin(),x.end()),x.end());
  sort(y.begin(),y.end());y.erase(unique(y.begin(),y.end()),y.end());
  ll ans = LONG_LONG_MAX;
  ll ansx,ansy;
  rep(i,y.size()){
    rep(j,x.size()){
      vector<ll> dist;
      rep(k,in.size()){
	dist.push_back(myabs(in[k].second,x[j])+myabs(in[k].first,y[i]));
      }
      sort(dist.begin(),dist.end());
      ll tmp = 0;
      rep(k,dist.size()){
	tmp += dist[k]*2;
      }
      tmp -= dist[dist.size()-1];
      if (tmp < ans){
	ans = tmp;
	ansy = x[j];
	ansx = y[i];
      }else if (tmp == ans && x[j] < ansx){
	ans = tmp;
	ansx = x[j];
	ansy = y[i];
      }else if (tmp == ans && x[j] == ansx && y[i] < ansy){
	ans = tmp;
	ansx = x[j];
	ansy = y[i];
      }
    }
  }
  cout << "brute force " << endl;
  cout << ans <<endl << ansx <<" " << ansy << endl;
}

main(){
  int w,h,n;
  while(cin>>w>>h>>n){
    vector<pair<ll,ll> > in(n);
    //input is x,y
    rep(i,n){
      cin>>in[i].first>>in[i].second;
    }
    vector<pli> y,x;//XRAAÀWÌyA
    map<ll,int> Y,X;
    precalc(in,y,Y);
    rep(i,n)swap(in[i].first,in[i].second);
    precalc(in,x,X);
    rep(i,n)swap(in[i].first,in[i].second);

    //ð­
    int mx = 0,my=0;
    rep(i,x.size())if (x[i].first < x[mx].first)mx = i;
    rep(i,y.size())if (y[i].first < y[my].first)my = i;    

    const int D=10;
    ll ans = LONG_LONG_MAX;
    ll ansx,ansy;
    rep(k,(int)in.size()){
      //æè­yÀWÌCfbNX,æè­ÀWnkÍin[k].first,in[k].second
      int xind = X[in[k].second];
      int yind = Y[in[k].first ];
      //¦ÌêðßéB(i,j)
      REP(i,max(0,yind-D),min(yind+D,(int)Y.size())){
	REP(j,max(0,xind-D),min(xind+D,(int)X.size())){
	  //¦ÌêÌAðæè©È©Á½lðßé
	  ll tmp = (ll)y[i].first + (ll)x[j].first;
	  tmp -= myabs((ll)y[i].second,(ll)in[k].first);
	  tmp -= myabs((ll)x[j].second,(ll)in[k].second); 
	  ll ty=y[i].second,tx=x[j].second;
	  if (tmp < ans){
	    ans = tmp;
	    ansx = tx;
	    ansy = ty;
	  }else if (tmp == ans && tx < ansx){
	    ans = tmp;
	    ansx = tx;
	    ansy = ty;
	  }else if (tmp == ans && tx == ansx && ty < ansy){
	    ans = tmp;
	    ansx = tx;
	    ansy = ty;
	  }
	}
      }

      REP(i,max(0,my-D),min(my+D,(int)Y.size())){
	REP(j,max(0,mx-D),min(mx+D,(int)X.size())){
	  //¦ÌêÌAðæè©È©Á½lðßé
	  ll tmp = (ll)y[i].first + (ll)x[j].first;
	  tmp -= myabs((ll)y[i].second,(ll)in[k].first);
	  tmp -= myabs((ll)x[j].second,(ll)in[k].second); 
	  ll ty=y[i].second,tx=x[j].second;
	  if (tmp < ans){
	    ans = tmp;
	    ansx = tx;
	    ansy = ty;
	  }else if (tmp == ans && tx < ansx){
	    ans = tmp;
	    ansx = tx;
	    ansy = ty;
	  }else if (tmp == ans && tx == ansx && ty < ansy){
	    ans = tmp;
	    ansx = tx;
	    ansy = ty;
	  }
	}
      }

    }
    cout << ans << endl << ansy <<" " << ansx << endl;
    //bf(in);
  }
}

Compiler output:
a.cc:1:1: error: extended character  is not valid in an identifier
    1 | è³ÅACµ½ÌÉAOJ¾ÆWAÉÈÁÄßµ¢
      | ^
a.cc:1:1: error: extended character  is not valid in an identifier
a.cc:1:1: error: extended character  is not valid in an identifier
a.cc:1:1: error: extended character  is not valid in an identifier
a.cc:1:1: error: extended character  is not valid in an identifier
a.cc:1:1: error: extended character  is not valid in an identifier
a.cc:1:1: error: extended character  is not valid in an identifier
a.cc:1:1: error: extended character  is not valid in an identifier
a.cc:1:1: error: extended character  is not valid in an identifier
a.cc:1:1: error: extended character  is not valid in an identifier
a.cc:1:1: error: extended character  is not valid in an identifier
a.cc:1:1: error: extended character  is not valid in an identifier
a.cc:1:1: error: extended character  is not valid in an identifier
a.cc:1:1: error: extended character  is not valid in an identifier
a.cc:1:1: error: extended character  is not valid in an identifier
a.cc:1:1: error: extended character  is not valid in an identifier
a.cc:1:1: error: extended character ¢ is not valid in an identifier
a.cc:1:1: error: '\302\216\303\250\302\214\302\263\302\202\303\205AC\302\202\302\265\302\202\302\275\302\202\303\214\302\202\303\211AOJ\302\202\302\276\302\202\303\206WA\302\202\303\211\302\202\303\210\302\202\303\201\302\202\303\204\302\224\303\237\302\202\302\265\302\202\302\242' does not name a type
    1 | è³ÅACµ½ÌÉAOJ¾ÆWAÉÈÁÄßµ¢
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/iosfwd:42,
                 from /usr/include/c++/14/ios:40,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:2:
/usr/include/c++/14/bits/postypes.h:68:11: error: 'ptrdiff_t' does not name a type
   68 |   typedef ptrdiff_t     streamsize; // Signed integral type
      |           ^~~~~~~~~
/usr/include/c++/14/bits/postypes.h:41:1: note: 'ptrdiff_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
   40 | #include <cwchar> // For mbstate_t
  +++ |+#include <cstddef>
   41 | 
In file included from /usr/include/c++/14/bits/exception_ptr.h:38,
                 from /usr/include/c++/14/exception:166,
                 from /usr/include/c++/14/ios:41:
/usr/include/c++/14/new:131:26: error: declaration of 'operator new' as non-function
  131 | _GLIBCXX_NODISCARD void* operator new(std::size_t) _GLIBCXX_THROW (std::bad_alloc)
      |                          ^~~~~~~~
/usr/include/c++/14/new:131:44: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
  131 | _GLIBCXX_NODISCARD void* operator new(std::size_t) _GLIBCXX_THROW (std::bad_alloc)
      |                                            ^~~~~~
In file included from /usr/include/wchar.h:35,
                 from /usr/include/c++/14/cwchar:44,
                 from /usr/include/c++/14/bits/postypes.h:40:
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
  214 | typedef __SIZE_TYPE__ size_t;
      |                       ^~~~~~
/usr/include/c++/14/new:132:41: error: attributes after parenthesized initializer ignored [-fpermissive]
  132 |   __attribute__((__externally_visible__));
      |                                         ^
/usr/include/c++/14/new:133:26: error: declaration of 'operator new []' as non-function
  133 | _GLIBCXX_NODISCARD void* operator new[](std::size_t) _GLIBCXX_THROW (std::bad_alloc)
      |                          ^~~~~~~~
/usr/include/c++/14/new:133:46: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
  133 | _GLIBCXX_NODISCARD void* operator new[](std::size_t) _GLIBCXX_THROW (std::bad_alloc)
      |                                              ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
  214 | typedef __SIZE_TYPE__ size_t;
      |                       ^~~~~~
/usr/include/c++/14/new:134:41: error: attributes after parenthesized initializer ignored [-fpermissive]
  134 |   __attribute__((__externally_visible__));
      |                                         ^
/usr/include/c++/14/new:140:29: error: 'std::size_t' has not been declared
  140 | void operator delete(void*, std::size_t) _GLIBCXX_USE_NOEXCEPT
      |                             ^~~
/usr/include/c++/14/new:142:31: error: 'std::size_t' has not been declared
  142 | void operator delete[](void*, std::size_t) _GLIBCXX_USE_NOEXCEPT
      |                               ^~~
/usr/include/c++/14/new:145:26: error: declaration of 'operator new' as non-function
  145 | _GLIBCXX_NODISCARD void* operator new(std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
      |                          ^~~~~~~~
/usr/include/c++/14/new:145:44: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
  145 | _GLIBCXX_NODISCARD void* operator new(std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
      |                                            ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
  214 | typedef __SIZE_TYPE__ size_t;
      |                       ^~~~~~
/usr/include/c++/14/new:145:52: error: expected primary-expression before 'const'
  145 | _GLIBCXX_NODISCARD void* operator new(std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
      |                                                    ^~~~~
/usr/include/c++/14/new:147:26: error: declaration of 'operator new []' as non-function
  147 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
      |                          ^~~~~~~~
/usr/include/c++/14/new:147:46: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
  147 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
      |                                              ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
  214 | typedef __SIZE_TYPE__ size_t;
      |                       ^~~~~~
/usr/include/c++/14/new:147:54: error: expected primary-expression before 'const'
  147 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
      |                                                      ^~~~~
/usr/include/c++/14/new:154:26: error: declaration of 'operator new' as non-function
  154 | _GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t)
      |                          ^~~~~~~~
/usr/include/c++/14/new:154:44: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
  154 | _GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t)
      |                                            ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
  214 | typedef __SIZE_TYPE__ size_t;
      |                       ^~~~~~
/usr/include/c++/14/new:154:68: error: expected primary-expression before ')' token
  154 | _GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t)
      |                                                                    ^
/usr/include/c++/14/new:155:73: error: attributes after parenthesized initializer ignored [-fpermissive]
  155 |   __attribute__((__externally_visible__, __alloc_size__ (1), __malloc__));
      |                                                                         ^
/usr/include/c++/14/new:156:26: error: declaration of 'operator new' as non-function
  156 | _GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t, const std::nothrow_t&)
      |                          ^~~~~~~~
/usr/include/c++/14/new:156:44: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
  156 | _GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t, const std::nothrow_t&)
      |                                            ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
  214 | typedef __SIZE_TYPE__ size_t;
      |                       ^~~~~~
/usr/include/c++/14/new:156:68: error: expected primary-expression before ',' token
  156 | _GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t, const std::nothrow_t&)
      |                                                                    ^
/usr/include/c++/14/new:156:70: error: expected primary-expression before 'const'
  156 | _GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t, const std::nothrow_t&)
      |                                                                      ^~~~~
/usr/include/c++/14/new:162:26: error: declaration of 'operator new []' as non-function
  162 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, std::align_val_t)
      |                          ^~~~~~~~
/usr/include/c++/14/new:162:46: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
  162 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, std::align_val_t)
      |                                              ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
  214 | typedef __SIZE_TYPE__ size_t;
      |                       ^~~~~~
/usr/include/c++/14/new:162:70: error: expected primary-expression before ')' token
  162 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, std::align_val_t)
      |                                                                      ^
/usr/include/c++/14/new:163:73: error: attributes after parenthesized initializer ignored [-fpermissive]
  163 |   __attribute__((__externally_visible__, __alloc_size__ (1), __malloc__));
      |                                                                         ^
/usr/include/c++/14/new:164:26: error: declaration of 'operator new []' as non-function
  164 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, std::align_val_t, const std::nothrow_t&)
      |                          ^~~~~~~~
/usr/include/c++/14/new:164:46: error: 'size_t' is not a member o