Problem p03576 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define maxn 100005
#define ll long long
#define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
#define rc(s) return cout << s, 0
#define _                                                                      \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cerr.tie(0);                                                                 \
  cout.tie(0);
#define db(x) cerr << #x << " = " << x << '\n'
#define pb push_back
#define mp make_pair
#define sz(x) (int)((x).size())
#define int ll
using namespace std;

int n, k, x, y;
int ans = 4e18;
vector<pair<int, int>> vecx, vecy;
int a[100];
int b[100];
int knt[100];
int cnt[100][100];
int sum[100];

int32_t main() {
  _ freopen("input", "r", stdin);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> x >> y;
    vecx.pb(mp(x, i));
    vecy.pb(mp(y, i));
  }
  sort(vecx.begin(), vecx.end());
  sort(vecy.begin(), vecy.end());
  for (int i = 0; i < sz(vecx); i++)
    a[vecx[i].second] = i + 1;
  for (int i = 0; i < sz(vecy); i++)
    b[vecy[i].second] = i + 1;
  for (int i = 1; i <= n; i++) {
    cnt[a[i]][b[i]]++;
    cnt[a[i]][b[i]] += cnt[a[i]][b[i] - 1];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++)
      knt[j] = 0;
    for (int j = i; j <= n; j++) {
      for (int jj = 1; jj <= n; jj++) {
        knt[jj] += cnt[j][jj];
      }
      memset(sum, 0, sizeof(sum));
      for (int jj = 1; jj <= n; jj++)
        sum[jj] = knt[jj] + sum[jj - 1];
      for (int x = 1; x <= n; x++) {
        for (int y = x; y <= n; y++) {
          if (sum[y] - sum[x - 1] >= k)
            ans = min(ans, (vecx[j - 1].first - vecx[i - 1].first) *
                               (vecy[y - 1].first - vecy[x - 1].first));
        }
      }
    }
  }
  rc(ans);
}


Fixed submission:
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define maxn 100005
#define ll long long
#define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
#define rc(s) return cout << s, 0
#define _                                                                      \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cerr.tie(0);                                                                 \
  cout.tie(0);
#define db(x) cerr << #x << " = " << x << '\n'
#define pb push_back
#define mp make_pair
#define sz(x) (int)((x).size())
#define int ll
using namespace std;

int n, k, x, y;
int ans = 4e18;
vector<pair<int, int>> vecx, vecy;
int a[100];
int b[100];
int knt[100];
int cnt[100][100];
int sum[100];

int32_t main() {
  _
          // freopen("input","r",stdin);
          cin >>
      n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> x >> y;
    vecx.pb(mp(x, i));
    vecy.pb(mp(y, i));
  }
  sort(vecx.begin(), vecx.end());
  sort(vecy.begin(), vecy.end());
  for (int i = 0; i < sz(vecx); i++)
    a[vecx[i].second] = i + 1;
  for (int i = 0; i < sz(vecy); i++)
    b[vecy[i].second] = i + 1;
  for (int i = 1; i <= n; i++) {
    cnt[a[i]][b[i]]++;
    cnt[a[i]][b[i]] += cnt[a[i]][b[i] - 1];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++)
      knt[j] = 0;
    for (int j = i; j <= n; j++) {
      for (int jj = 1; jj <= n; jj++) {
        knt[jj] += cnt[j][jj];
      }
      memset(sum, 0, sizeof(sum));
      for (int jj = 1; jj <= n; jj++)
        sum[jj] = knt[jj] + sum[jj - 1];
      for (int x = 1; x <= n; x++) {
        for (int y = x; y <= n; y++) {
          if (sum[y] - sum[x - 1] >= k)
            ans = min(ans, (vecx[j - 1].first - vecx[i - 1].first) *
                               (vecy[y - 1].first - vecy[x - 1].first));
        }
      }
    }
  }
  rc(ans);
}