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

using namespace std;
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define IOS                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define repa(i, a, b) for (int i = a; i <= b; i++)
#define repd(i, b, a) for (int i = b; i >= a; i--)
#define endl "\\n"
// debugging
#define debug1(a) cout << #a << " = " << (a) << endl;
#define debug2(a, b)                                                           \\
  cout << #a << " = " << (a) << ", " << #b << " = " << (b) << endl;
#define debug3(a, b, c)                                                        \\
  cout << #a << " = " << (a) << ", " << #b << " = " << (b) << ", " << #c       \\
       << " = " << (c) << endl;
#define debug4(a, b, c, d)                                                     \\
  cout << #a << " = " << (a) << ", " << #b << " = " << (b) << ", " << #c       \\
       << " = " << (c) << ", " << #d << " = " << (d) << endl;

const int N = 1e+6 + 5;
int big = 1e+18 + 3;
int mod = 1e+9 + 7;

signed main() {
  IOS;

  int n, m;

  cin >> n >> m;

  int ar[n + 1];

  int sum = 0;

  repa(i, 1, n) {
    cin >> ar[i];
    sum += ar[i];
    ar[i] *= (4 * m);
  }

  int cnt = 0;

  repa(i, 1, n) cnt += (ar[i] >= sum);

  if (cnt >= m)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Error: -11

Fixed submission:

using namespace std;
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define IOS                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define repa(i, a, b) for (int i = a; i <= b; i++)
#define repd(i, b, a) for (int i = b; i >= a; i--)
#define endl "\\n"
// debugging
#define debug1(a) cout << #a << " = " << (a) << endl;
#define debug2(a, b)                                                           \\
  cout << #a << " = " << (a) << ", " << #b << " = " << (b) << endl;
#define debug3(a, b, c)                                                        \\
  cout << #a << " = " << (a) << ", " << #b << " = " << (b) << ", " << #c       \\
       << " = " << (c) << endl;
#define debug4(a, b, c, d)                                                     \\
  cout << #a << " = " << (a) << ", " << #b << " = " << (b) << ", " << #c       \\
       << " = " << (c) << ", " << #d << " = " << (d) << endl;

const int N = 1e+6 + 5;
int big = 1e+18 + 3;
int mod = 1e+9 + 7;

signed main() {
  IOS;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  int n, m;
  cin >> n >> m;
  int ar[n + 1];
  int sum = 0;

  repa(i, 1, n) {
    cin >> ar[i];
    ar[i] *= m;
    ar[i] *= 4;
    sum += ar[i];
  }

  int val = sum / (4 * m);

  int cnt = 0;

  repa(i, 1, n) if (ar[i] >= val) cnt++;

  if (cnt >= m)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}