Problem p02718 (C++) — buggy submission, verdict: Runtime Error

// Bismillahir Rahmanir Rahim
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define ms(a, b) memset(a, b, sizeof(a))
#define filein freopen("input.txt", "r", stdin);
#define fileout freopen("output.txt", "w", stdout);
#define debug cout << "Hello, i am in here." << endl;
#define bit_cnt(mask) __builtin_popcountll(mask)
#define ll long long int
#define dst(u, v, x, y)                                                        \\
  sqrt((x * 1.0 - u * 1.0) * (x * 1.0 - u * 1.0) +                             \\
       (y * 1.0 - v * 1.0) * (y * 1.0 - v * 1.0))
template <class T> inline T bigmod(T p, T e, T M) {
  ll ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1)
      ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T> inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
} // M is prime}
template <class T> inline T bpow(T p, T e) {
  ll ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1)
      ret = (ret * p);
    p = (p * p);
  }
  return (T)ret;
}
using namespace std;
const int MOD = (int)1e9 + 7;
void solve() {
  ll n, m;
  cin >> n >> m;
  vector<ll> nums;
  ll sum = 0;
  for (int i = 1; i <= n; i++) {
    ll a;
    cin >> a;
    nums.push_back(a);
    sum += a;
  }
  sort(nums.rbegin(), nums.rend());
  double lagbe = (1 / (4 * m * 1.0)) * (sum * 1.0);
  int Count = 0;
  for (int i = 0; i < n; i++) {
    if (nums[i] >= lagbe) {
      Count++;
      if (Count == m) {
        cout << "Yes" << endl;
        return;
      }
    }
  }
  cout << "No" << endl;
  return;
}
int main() {
  IOS solve();
  return 0;
}


Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

// Bismillahir Rahmanir Rahim
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define ms(a, b) memset(a, b, sizeof(a))
#define filein freopen("input.txt", "r", stdin);
#define fileout freopen("output.txt", "w", stdout);
#define debug cout << "Hello, i am in here." << endl;
#define bit_cnt(mask) __builtin_popcountll(mask)
#define ll long long int
#define dst(u, v, x, y)                                                        \\
  sqrt((x * 1.0 - u * 1.0) * (x * 1.0 - u * 1.0) +                             \\
       (y * 1.0 - v * 1.0) * (y * 1.0 - v * 1.0))
template <class T> inline T bigmod(T p, T e, T M) {
  ll ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1)
      ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T> inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
} // M is prime}
template <class T> inline T bpow(T p, T e) {
  ll ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1)
      ret = (ret * p);
    p = (p * p);
  }
  return (T)ret;
}
using namespace std;
const int MOD = (int)1e9 + 7;
void solve() {
  ll n, m;
  cin >> n >> m;
  vector<ll> nums;
  ll sum = 0;
  for (int i = 1; i <= n; i++) {
    ll a;
    cin >> a;
    nums.push_back(a);
    sum += a;
  }
  sort(nums.rbegin(), nums.rend());
  double lagbe = (1 / (4 * m * 1.0)) * (sum * 1.0);
  int Count = 0;
  for (int i = 0; i < n; i++) {
    if (nums[i] >= lagbe) {
      Count++;
      if (Count == m) {
        cout << "Yes" << endl;
        return;
      }
    }
  }
  cout << "No" << endl;
  return;
}
int main() {
  IOS
#ifndef ONLINE_JUDGE
      filein
#else
// online submission
#endif
      solve();
  return 0;
}