Language: C++

#include <iostream>
#include <vector>
using namespace std;


int main(void){
  int n, k;  cin >> n >> k;

  vector<int> x, y;
  int xin, yin;
  for(int i=0; i<n; i++){
    cin >> xin >> yin;
    x.push_back(xin);
    y.push_back(yin);
  }

  bool xymM[4] = {false, false, false, false};
  int maxX = x[0], maxY = y[0];
  int minX = x[0], minY = y[0];
  int maxX2 = min(x[0], x[1]), maxY2 = min(y[0], y[1]);
  int minX2 = max(x[0], x[1]), minY2 = max(y[0], y[1]);
  for(int i=0; i<n; i++){
    if(x[i] < minX){ minX2 = minX;  minX = x[i]; }
    else if(x[i] < minX2){minX2 = x[i];}

    if(x[i] > maxX){ maxX2 = maxX;  maxX = x[i]; }
    else if(x[i] > maxX2){ maxX2 = x[i]; }

    if(y[i] < minY){ minY2 = minY;  minY = y[i]; }
    else if(y[i] < minY2){ minY2 = y[i]; }

    if(y[i] > maxY){ maxY2 = maxY;  maxY = y[i]; }
    else if(y[i] > maxY2){ maxY2 = y[i]; }
  }
  x.erase(x.begin() + distance(x.begin(), maxX) );
  x.erase(x.begin() + distance(x.begin(), minX) );
  y.erase(y.begin() + distance(y.begin(), maxY) );
  y.erase(y.begin() + distance(y.begin(), minY) );

  unsigned long long S;
  for(int j=0; j<n-k; j++){
    if(xymM[0]){
      maxX = maxX2;
      x.erase(x.begin() + distance(x.begin(), maxX) );
      maxX2 = *max_element(x.begin(), x.end());
    }else if(xymM[1]){
      minX = minX2;
      x.erase(x.begin() + distance(x.begin(), minX) );
      minX2 = *min_element(x.begin(), x.end());
    }else if(xymM[2]){
      maxY = maxY2;
      y.erase(y.begin() + distance(y.begin(), maxY) );
      maxY2 = *max_element(y.begin(), y.end());
    }else if(xymM[3]){
      minY = minY2;
      y.erase(y.begin() + distance(y.begin(), minY) );
      minY2 = minY2;
      minY2 = *min_element(y.begin(), y.end());
    }

    S = (maxX - minX) * (maxY - minY2);
    fill(xymM, xymM+4, false); xymM[3] = true;

    if(S > (maxX-minX)*(maxY2-minY)){
      S = (maxX-minX)*(maxY2-minY);
      fill(xymM, xymM+4, false); xymM[2] = true;
    }
    if(S > (maxX-minX2)*(maxY-minY)){
      S = (maxX-minX2)*(maxY-minY);
      fill(xymM, xymM+4, false); xymM[1] = true;
    }
    if(S > (maxX2-minX)*(maxY-minY)){
      S = (maxX2-minX)*(maxY-minY);
      fill(xymM, xymM+4, false); xymM[0] = true;
    }
  }

  cout << ans << endl;

  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:35:31: error: no matching function for call to 'distance(std::vector<int>::iterator, int&)'
   35 |   x.erase(x.begin() + distance(x.begin(), maxX) );
      |                       ~~~~~~~~^~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:47,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:148:5: note: candidate: 'template<class _InputIterator> constexpr typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::distance(_InputIterator, _InputIterator)'
  148 |     distance(_InputIterator __first, _InputIterator __last)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:148:5: note:   template argument deduction/substitution failed:
a.cc:35:31: note:   deduced conflicting types for parameter '_InputIterator' ('__gnu_cxx::__normal_iterator<int*, std::vector<int> >' and 'int')
   35 |   x.erase(x.begin() + distance(x.begin(), maxX) );
      |                       ~~~~~~~~^~~~~~~~~~~~~~~~~
a.cc:36:31: error: no matching function for call to 'distance(std::vector<int>::iterator, int&)'
   36 |   x.erase(x.begin() + distance(x.begin(), minX) );
      |                       ~~~~~~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:148:5: note: candidate: 'template<class _InputIterator> constexpr typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::distance(_InputIterator, _InputIterator)'
  148 |     distance(_InputIterator __first, _InputIterator __last)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:148:5: note:   template argument deduction/substitution failed:
a.cc:36:31: note:   deduced conflicting types for parameter '_InputIterator' ('__gnu_cxx::__normal_iterator<int*, std::vector<int> >' and 'int')
   36 |   x.erase(x.begin() + distance(x.begin(), minX) );
      |                       ~~~~~~~~^~~~~~~~~~~~~~~~~
a.cc:37:31: error: no matching function for call to 'distance(std::vector<int>::iterator, int&)'
   37 |   y.erase(y.begin() + distance(y.begin(), maxY) );
      |                       ~~~~~~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:148:5: note: candidate: 'template<class _InputIterator> constexpr typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::distance(_InputIterator, _InputIterator)'
  148 |     distance(_InputIterator __first, _InputIterator __last)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:148:5: note:   template argument deduction/substitution failed:
a.cc:37:31: note:   deduced conflicting types for parameter '_InputIterator' ('__gnu_cxx::__normal_iterator<int*, std::vector<int> >' and 'int')
   37 |   y.erase(y.begin() + distance(y.begin(), maxY) );
      |                       ~~~~~~~~^~~~~~~~~~~~~~~~~
a.cc:38:31: error: no matching function for call to 'distance(std::vector<int>::iterator, int&)'
   38 |   y.erase(y.begin() + distance(y.begin(), minY) );
      |                       ~~~~~~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:148:5: note: candidate: 'template<class _InputIterator> constexpr typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::distance(_InputIterator, _InputIterator)'
  148 |     distance(_InputIterator __first, _InputIterator __last)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:148:5: note:   template argument deduction/substitution failed:
a.cc:38:31: note:   deduced conflicting types for parameter '_InputIterator' ('__gnu_cxx::__normal_iterator<int*, std::vector<int> >' and 'int')
   38 |   y.erase(y.begin() + distance(y.begin(), minY) );
      |                       ~~~~~~~~^~~~~~~~~~~~~~~~~
a.cc:44:35: error: no matching function for call to 'distance(std::vector<int>::iterator, int&)'
   44 |       x.erase(x.begin() + distance(x.begin(), maxX) );
      |                           ~~~~~~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:148:5: note: candidate: 'template<class _InputIterator> constexpr typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::distance(_InputIterator, _InputIterator)'
  148 |     distance(_InputIterator __first, _InputIterator __last)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:148:5: note:   template argument deduction/substitution failed:
a.cc:44:35: note:   deduced conflicting types for parameter '_InputIterator' ('__gnu_cxx::__normal_iterator<int*, std::vector<int> >' and 'int')
   44 |       x.erase(x.begin() + distance(x.begin(), maxX) );
      |                           ~~~~~~~~^~~~~~~~~~~~~~~~~
a.cc:45:16: error: 'max_element' was not declared in this scope
   45 |       maxX2 = *max_element(x.begin(), x.end());
      |                ^~~~~~~~~~~
a.cc:48:35: error: no matching function for call to 'distance(std::vector<int>::iterator, int&)'
   48 |       x.erase(x.begin() + distance(x.begin(), minX) );
      |                           ~~~~~~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:148:5: note: candidate: 'template<class _InputIterator> constexpr typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::distance(_InputIterator, _InputIterator)'
  148 |     distance(_InputIterator __first, _InputIterator __last)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:148:5: note:   template argument deduction/substitution failed:
a.cc:48:35: note:   deduced conflicting types for parameter '_InputIterator' ('__gnu_cxx::__normal_iterator<int*, std::vector<int> >' and 'int')
   48 |       x.erase(x.begin() + distance(x.begin(), minX) );
      |                           ~~~~~~~~^~~~~~~~~~~~~~~~~
a.cc:49:16: error: 'min_element' was not declared in this scope
   49 |       minX2 = *min_element(x.begin(), x.end());
      |                ^~~~~~~~~~~
a.cc:52:35: error: no matching function for call to 'distance(std::vector<int>::iterator, int&)'
   52 |       y.erase(y.begin() + distance(y.begin(), maxY) );
      |                           ~~~~~~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:148:5: note: candidate: 'template<class _InputIterator> constexpr typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::distance(_InputIterator, _InputIterator)'
  148 |     distance(_InputIterator __first, _InputIterator __last)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:148:5: note:   template argument deduction/substitution failed:
a.cc:52:35: note:   deduced conflicting types for parameter '_InputIterator' ('__gnu_cxx::__normal_iterator<int*, std::vector<int> >' and 'int')
   52 |       y.erase(y.begin() + distance(y.begin(), maxY) );
      |                           ~~~~~~~~^~~~~~~~~~~~~~~~~
a.cc:53:16: error: 'max_element' was not declared in this scope
   53 |       maxY2 = *max_element(y.begin(), y.end());
      |                ^~~~~~~~~~~
a.cc:56:35: error: no matching function for call to 'distance(std::vector<int>::iterator, int&)'
   56 |       y.erase(y.begin() + distance(y.begin(), minY) );
      |                           ~~~~~~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:148:5: note: candidate: 'template<class _InputIterator> constexpr typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::distance(_InputIterator, _InputIterator)'
  148 |     distance(_InputIterator __first, _InputIterator __last)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:148:5: note:   template argument deduction/substitution failed:
a.cc:56:35: note:   deduced conflicting types for parameter '_InputIterator' ('__gnu_cxx::__normal_iterator<int*, std::vector<int> >' and 'int')
   56 |       y.erase(y.begin() + distance(y.begin(), minY) );
      |                           ~~~~~~~~^~~~~~~~~~~~~~~~~
a.cc:58:16: error: 'min_element' was not declared in this scope
   58 |       minY2 = *min_element(y.begin(), y.end());
      |                ^~~~~~~~~~~
a.cc:78:11: error: 'ans' was not declared in this scope; did you mean 'abs'?
   78 |   cout << ans << endl;
      |           ^~~
      |           abs