Language: C++

#include <iostream>
#include <algorithm>
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:9:3: error: 'vector' was not declared in this scope
    9 |   vector<int> x, y;
      |   ^~~~~~
a.cc:3:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    2 | #include <algorithm>
  +++ |+#include <vector>
    3 | using namespace std;
a.cc:9:10: error: expected primary-expression before 'int'
    9 |   vector<int> x, y;
      |          ^~~
a.cc:13:5: error: 'x' was not declared in this scope
   13 |     x.push_back(xin);
      |     ^
a.cc:14:5: error: 'y' was not declared in this scope
   14 |     y.push_back(yin);
      |     ^
a.cc:18:14: error: 'x' was not declared in this scope
   18 |   int maxX = x[0], maxY = y[0];
      |              ^
a.cc:29:8: error: 'y' was not declared in this scope
   29 |     if(y[i] < minY){ minY2 = minY;  minY = y[i]; }
      |        ^
a.cc:29:15: error: 'minY' was not declared in this scope; did you mean 'minX'?
   29 |     if(y[i] < minY){ minY2 = minY;  minY = y[i]; }
      |               ^~~~
      |               minX
a.cc:29:22: error: 'minY2' was not declared in this scope; did you mean 'minX2'?
   29 |     if(y[i] < minY){ minY2 = minY;  minY = y[i]; }
      |                      ^~~~~
      |                      minX2
a.cc:30:20: error: 'minY2' was not declared in this scope; did you mean 'minX2'?
   30 |     else if(y[i] < minY2){ minY2 = y[i]; }
      |                    ^~~~~
      |                    minX2
a.cc:32:8: error: 'y' was not declared in this scope
   32 |     if(y[i] > maxY){ maxY2 = maxY;  maxY = y[i]; }
      |        ^
a.cc:32:15: error: 'maxY' was not declared in this scope; did you mean 'maxX'?
   32 |     if(y[i] > maxY){ maxY2 = maxY;  maxY = y[i]; }
      |               ^~~~
      |               maxX
a.cc:32:22: error: 'maxY2' was not declared in this scope; did you mean 'maxX2'?
   32 |     if(y[i] > maxY){ maxY2 = maxY;  maxY = y[i]; }
      |                      ^~~~~
      |                      maxX2
a.cc:33:20: error: 'maxY2' was not declared in this scope; did you mean 'maxX2'?
   33 |     else if(y[i] > maxY2){ maxY2 = y[i]; }
      |                    ^~~~~
      |                    maxX2
a.cc:37:3: error: 'y' was not declared in this scope
   37 |   y.erase(y.begin() + distance(y.begin(), maxY) );
      |   ^
a.cc:37:43: error: 'maxY' was not declared in this scope; did you mean 'maxX'?
   37 |   y.erase(y.begin() + distance(y.begin(), maxY) );
      |                                           ^~~~
      |                                           maxX
a.cc:38:43: error: 'minY' was not declared in this scope; did you mean 'minX'?
   38 |   y.erase(y.begin() + distance(y.begin(), minY) );
      |                                           ^~~~
      |                                           minX
a.cc:51:14: error: 'maxY2' was not declared in this scope; did you mean 'maxX2'?
   51 |       maxY = maxY2;
      |              ^~~~~
      |              maxX2
a.cc:55:14: error: 'minY2' was not declared in this scope; did you mean 'minX2'?
   55 |       minY = minY2;
      |              ^~~~~
      |              minX2
a.cc:61:33: error: 'minY2' was not declared in this scope; did you mean 'minX2'?
   61 |     S = (maxX - minX) * (maxY - minY2);
      |                                 ^~~~~
      |                                 minX2
a.cc:64:25: error: 'maxY2' was not declared in this scope; did you mean 'maxX2'?
   64 |     if(S > (maxX-minX)*(maxY2-minY)){
      |                         ^~~~~
      |                         maxX2
a.cc:78:11: error: 'ans' was not declared in this scope; did you mean 'abs'?
   78 |   cout << ans << endl;
      |           ^~~
      |           abs