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

#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<ll> vi;

#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define nl cout << '\\n'
#define pb push_back
#define all(s) s.begin(), s.end()
#define bs binary_search

#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) (a) * (b) / (__gcd((a), (b)))

const int Mod = 1e9 + 7;
#define sum(a, b) (((a) % Mod) + ((b) % Mod)) % Mod
#define sub(a, b) (((a) % Mod) - ((b) % Mod)) % Mod
#define mul(a, b) (((a) % Mod) * ((b) % Mod)) % Mod
#define digit(x) floor((log10(x)) + 1)

#define count1(x) __builtin_popcount(x)

#define dbg(x) cout << #x << ":" << x << endl;

bool isPowerOfTwo(int x) {
  /* First x in the below expression is for the case when x is 0 */
  return x && (!(x & (x - 1)));
}

ll pow(ll x, ll y, ll mod) {
  int ans = 1;
  while (y) {
    if (y & 1)
      ans = (ans * x) % mod;
    y /= 2;
    x = (x * x) % mod;
  }
  return ans;
}

int main() {
  fast;
  ll n, m, sum, i, count;
  cin >> n >> m;
  ll arr[n];
  sum = 0;
  for (i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
  }
  double crit;
  // dbg(sum);
  count = 0;
  crit = sum * 1.0 / (4 * m);
  // dbg(crit);
  for (i = 0; i < n; i++) {
    if (arr[i] * 1.0 < crit)
      continue;
    else
      count++;
  }
  // dbg(count);
  if (count >= m)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<ll> vi;

#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define nl cout << '\\n'
#define pb push_back
#define all(s) s.begin(), s.end()
#define bs binary_search

#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) (a) * (b) / (__gcd((a), (b)))

const int Mod = 1e9 + 7;
#define sum(a, b) (((a) % Mod) + ((b) % Mod)) % Mod
#define sub(a, b) (((a) % Mod) - ((b) % Mod)) % Mod
#define mul(a, b) (((a) % Mod) * ((b) % Mod)) % Mod
#define digit(x) floor((log10(x)) + 1)

#define count1(x) __builtin_popcount(x)

#define dbg(x) cout << #x << ":" << x << endl;

bool isPowerOfTwo(int x) {
  /* First x in the below expression is for the case when x is 0 */
  return x && (!(x & (x - 1)));
}

ll pow(ll x, ll y, ll mod) {
  int ans = 1;
  while (y) {
    if (y & 1)
      ans = (ans * x) % mod;
    y /= 2;
    x = (x * x) % mod;
  }
  return ans;
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("debug.txt", "w", stderr);
#endif
  fast;
  ll n, m, sum, i, count, crit;
  cin >> n >> m;
  ll arr[n];
  sum = 0;
  for (i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
  }
  count = 0;
  crit = sum / (4 * m);
  for (i = 0; i < n; i++) {
    if (arr[i] >= crit)
      count++;
    if (count == m)
      break;
  }
  if (count == m)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}