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, minX, maxY, minY;
  int maxX2, minX2, maxY2, minY2;
  vector<int>::iterator maxXi, minXi, maxYi, minYi;
  maxXi = max_element(x.begin(), x.end());
  minXi = min_element(x.begin(), x.end());
  maxYi = max_element(y.begin(), y.end());
  minYi = min_element(y.begin(), y.end());

  maxX = *maxXi;
  minX = *minXi;
  maxY = *maxYi;
  minY = *minYi;

  x.erase(x.begin() + distance(x.begin(), maxXi) );
  x.erase(x.begin() + distance(x.begin(), minXi) );
  y.erase(y.begin() + distance(y.begin(), maxYi) );
  y.erase(y.begin() + distance(y.begin(), minYi) );

  maxXi = max_element(x.begin(), x.end());
  minXi = min_element(x.begin(), x.end());
  maxYi = max_element(y.begin(), y.end());
  minYi = min_element(y.begin(), y.end());

  maxX2 = *maxXi;
  minX2 = *minXi;
  maxY2 = *maxYi;
  minY2 = *minYi;

  unsigned long long S = (maxX - minX) * (maxY - minY);

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

    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:21:11: error: 'max_element' was not declared in this scope
   21 |   maxXi = max_element(x.begin(), x.end());
      |           ^~~~~~~~~~~
a.cc:22:11: error: 'min_element' was not declared in this scope
   22 |   minXi = min_element(x.begin(), x.end());
      |           ^~~~~~~~~~~
a.cc:63:21: error: expected ';' before '}' token
   63 |       maxY2 = *maxYi
      |                     ^
      |                     ;
   64 |     }else if(xymM[3]){
      |     ~                
a.cc:66:35: error: no matching function for call to 'distance(std::vector<int>::iterator, int&)'
   66 |       y.erase(y.begin() + distance(y.begin(), minY) );
      |                           ~~~~~~~~^~~~~~~~~~~~~~~~~
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:66:35: note:   deduced conflicting types for parameter '_InputIterator' ('__gnu_cxx::__normal_iterator<int*, std::vector<int> >' and 'int')
   66 |       y.erase(y.begin() + distance(y.begin(), minY) );
      |                           ~~~~~~~~^~~~~~~~~~~~~~~~~
a.cc:88:11: error: 'ans' was not declared in this scope; did you mean 'abs'?
   88 |   cout << ans << endl;
      |           ^~~
      |           abs