alexjercan/bugnet huggingface dataset:
Problem p02718 (C++) — buggy submission, verdict: Runtime Error

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

int main() {

  int n, m; // N種類の商品とM個の人気商品 //A
  int sum = 0;
  int count = 0;

  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < n; i++) { // N個数分の商品
    cin >> a[i];
    sum += a[i];
  }

  for (int j = 0; j < n; j++) {
    if (a[j] * 4 * m >= sum) {
      count++;
    }
  }

  if (count >= m) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Error: -11

Fixed submission:

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

int main() {
  int n, m;      // N種類の商品とM個の人気商品
  vector<int> a; // A
  int sum = 0;
  int count = 0;

  cin >> n >> m;
  cout << endl;                 // 入力
  for (int i = 0; i < n; i++) { // N個数分の商品
    cin >> a[i];
    sum += a[i];
    if (a[i] > sum / (m * 4)) {
      count += 1;
    }
  }
  if (count == m) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p02718 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()

typedef long long ll;

void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  ll sum = 0;
  for (int x : a)
    sum += x;
  int good = 0;
  for (int x : a)
    if (x * 4ll * m >= sum)
      good++;
  cout << (good >= m ? "Yes" : "No");
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  solve();

  return 0;
}


Error: -8

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()

typedef long long ll;

void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> polls(n);
  ll tot = 0;
  for (int i = 0; i < n; ++i)
    cin >> polls[i], tot += polls[i];
  for (int i = 0; i < n; ++i) {
    if (polls[i] >= tot / (4 * m))
      --m;
  }
  cout << (m >= 0 ? "Yes" : "No");
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  solve();

  return 0;
}
Problem p02718 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef char chr;
typedef double dbl;
typedef long long int lld;
#define FastIO                                                                 \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
double getComb(double n, double x) {
  if (x > n) {
    return 0;
  } else {
    double r = 1.0;
    for (double i = 1.0; i <= x; i += 1) {
      double a = n - i + 1;
      double b = a / i;
      r *= b;
    }
    return r;
  }
}
int main() {
  FastIO lld n, i;
  dbl m;
  cin >> n;
  cin >> m;
  dbl A[n];
  lld c, t;
  t = 0;
  c = 0;
  dbl x = (1 / (4 * m));
  for (i = 0; i < n; i += 1) {
    cin >> A[i];
    t += A[i];
  }
  for (i = 0; i < n; i += 1) {
    if (A[i] >= (t * x)) {
      c += 1;
    }
  }
  if (c >= m)
    cout << "Yes\\n";
  else
    cout << "No\\n";
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef char chr;
typedef double dbl;
typedef long long int lld;
#define FastIO                                                                 \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
double getComb(double n, double x) {
  if (x > n) {
    return 0;
  } else {
    double r = 1.0;
    for (double i = 1.0; i <= x; i += 1) {
      double a = n - i + 1;
      double b = a / i;
      r *= b;
    }
    return r;
  }
}
int main() {
#ifndef ONLINE_JUDGE
  // for getting input from input.txt
  freopen("inputf.in", "r", stdin);
  // for writing output to output.txt
  freopen("outputf.in", "w", stdout);
#endif
  FastIO lld n, i;
  dbl m;
  cin >> n;
  cin >> m;
  dbl A[n];
  lld c, t;
  t = 0;
  c = 0;
  dbl x = (1 / (4 * m));
  for (i = 0; i < n; i += 1) {
    cin >> A[i];
    t += A[i];
  }
  for (i = 0; i < n; i += 1) {
    if (A[i] >= (t * x)) {
      c += 1;
    }
  }
  if (c > m)
    cout << "Yes\\n";
  else
    cout << "No\\n";
  return 0;
}
Problem p02718 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a[n];
  int sum = 0;
  for (int i = 0; i < n; i++)
    cin >> a[i], sum += a[i];
  sort(a, a + n);
  double thr = sum / ((4.0) * m);
  if (a[n - m] >= thr)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Error: 1

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
  int N, M, a[100], i, j, sum = 0;
  float test = 0.0;
  cin >> N >> M;
  for (i = 0; i < N; i++)
    cin >> a[i];

  for (i = 0; i < N; ++i) {
    for (j = 0; j < N - i - 1; ++j) {
      if (a[j] > a[j + 1]) {
        a[j] = a[j] + a[j + 1];
        a[j + 1] = a[j] - a[j + 1];
        a[j] = a[j] - a[j + 1];
      }
    }
  }
  for (i = 0; i < N; i++) {
    sum += a[i];
  }
  test = (1.0 / (4.0 * M)) * sum;

  if (a[N - M] >= test) {
    cout << "YES";
  } else
    cout << "NO";

  return 1;
}
Problem p02718 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int i, n, m, all = 0, p = 0; // n個の内、m個を選ぶ//
  cin >> n >> m;
  vector<int> a(n);
  for (i = 0; i < n; i++) {
    cin >> a[i];
    all = all + a[i];
  }
  for (i = 0; i < n; i++) {
    if ((4 * m) * a[i] >= all)
      p = p + 1;
  }

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

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int i, n, m, all = 0, p = 0; // n個の内、m個を選ぶ//
  cin >> n >> m;
  vector<int> a(i);
  for (i = 0; i < n; i++) {
    cin >> a[i];
    all = all + a[i];
  }
  for (i = 0; i < n; i++) {
    if ((4 * m) * a[i] >= all)
      p = p + 1;
  }

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

  return 0;
}
Problem p02718 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>; // グラフ型
typedef long long ll;
#define _GLIBCXX_DEBUG

int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> A(N);
  // vector<vector<int>> data(3, vector<int>(4));
  ll sum = 0;
  for (ll i = 0; i < N; i++) {
    cin >> A[i];
    sum += A[i];
  }

  sort(A.begin(), A.end(), greater<int>());

  for (ll i = 0; i < M; i++) {
    if ((4 * M * A[i]) < sum) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  // cout << sum << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>; // グラフ型
typedef long long ll;
#define _GLIBCXX_DEBUG
#define NN 1001

int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> A(N);
  // vector<vector<int>> data(3, vector<int>(4));
  ll sum = 0;
  for (ll i = 1; i <= N; i++) {
    cin >> A[i];
    sum += A[i];
  }

  sort(A.begin(), A.end(), greater<int>());

  for (ll i = 0; i < M; i++) {
    if ((4 * M * A[i]) < sum) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}
Problem p02718 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

int main(int argc, const char *argv[]) {

  cin.tie(0);
  ios::sync_with_stdio(false);

  /////////////////////
  // Write code below /
  /////////////////////
  int N, M, A[1000];
  float m, sum = 0, flag = 0;

  cin >> N >> M;
  m = M;
  rep(i, N) {
    cin >> A[i];
    sum += A[i];
  }

  sort(A, A + N, greater<int>());

  if (A[M - 1] < (sum / (4 * M))) {
    flag = 1;
  }

  if (flag == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Error: -8

Fixed submission:

#include <algorithm>
#include <fstream>
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;

int main(int argc, const char *argv[]) {

  cin.tie(0);
  ios::sync_with_stdio(false);

  /////////////////////
  // Write code below /
  /////////////////////
  int i, j, n, m, a[100], tmp, flug = 1;
  long long int sum = 0;
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }

  for (i = 0; i < n; ++i) {
    for (j = i + 1; j < n; ++j) {
      if (a[i] > a[j]) {
        tmp = a[i];
        a[i] = a[j];
        a[j] = tmp;
      }
    }
  }
  for (i = 0; i < m; i++) {
    if (a[i] < static_cast<double>(sum / (4 * i))) {
      flug = 0;
      break;
    }
  }
  if (flug != 0) {
    cout << "Yes\\n";
  } else {
    cout << "No\\n";
  }

  return 0;
}
Problem p02718 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {

  int N, M;
  cin >> N >> M;

  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }

  double sum = 0;
  for (int i = 0; i < N; i++) {
    sum += vec.at(i);
  }

  double stan = sum / (4 * M);

  sort(vec.begin(), vec.end());

  if (vec.at(N - M) >= stan) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 4) >= this->size() (which is 4)


Fixed submission:

#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {

  int N, M;
  cin >> N >> M;

  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }

  int sum = 0;
  for (int i = 0; i < N; i++) {
    sum += vec.at(i);
  }

  int stan = sum / 4 / M;

  sort(vec.begin(), vec.end());

  if (vec.at(N - M + 1) > stan) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p02718 (C++) — buggy submission, verdict: Runtime Error

/*************************************************************************
  > File Name: b.cpp
  > Author: Samuel
  > Mail: enminghuang21119@gmail.com
  > Created Time: Sat Apr  4 20:01:41 2020
*************************************************************************/

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

int in[1010];
int n, m;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> in[i];
    sum += in[i];
  }
  sum = sum / 4 / m + ((sum % (4 * m)) != 0);
  while (n--) {
    if (in[n] >= sum)
      m--;
  }
  cout << (m > 0 ? "No" : "Yes");
  return 0;
}


Error: 1

Fixed submission:

/*************************************************************************
  > File Name: b.cpp
  > Author: Samuel
  > Mail: enminghuang21119@gmail.com
  > Created Time: Sat Apr  4 20:01:41 2020
*************************************************************************/

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

int in[1010];
int n, m;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> in[i];
    sum += in[i];
  }
  sum /= 4 * m;
  while (n--) {
    if (in[n] >= sum)
      m--;
  }
  cout << (m >= 0 ? "No" : "Yes");
  return 1;
}
Problem p02718 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define pll pair<ll, ll>
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
const ll mod = 1000000007;

using namespace std;

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  ll tc = 1;

  //  cin >> tc;

  while (tc--) {
    ll k, n, i, maxm = 0, x, j, fl = 0;

    ll N, M;
    cin >> N >> M;

    std::vector<ll> A(N, 0);
    ll totvot = 0;

    for (i = 0; i < N; i++)
      cin >> A[i], totvot += A[i];

    ll ans = 0;
    for (i = 0; i < N; i++) {
      if (totvot <= 4 * M * A[i])
        ans++;
    }
    if (ans >= M)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
}


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


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define pll pair<ll, ll>
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
const ll mod = 1000000007;

using namespace std;

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  ll tc = 1;

  //  cin >> tc;

  while (tc--) {
    ll k, n, i1, i2, i, maxm = 0, x, j, fl = 0;

    ll N, M;
    cin >> N >> M;

    std::vector<ll> A(n, 0);
    ll totvot = 0;

    for (i = 0; i < N; i++)
      cin >> A[i], totvot += A[i];

    // totvot = totvot/(4*M);
    ll ans = 0;
    for (i = 0; i < N; i++) {
      if (totvot <= 4 * M * A[i])
        ans++;

      //	cout << 4*M*A[i];
    }
    //	cout << ans << endl;
    if (ans >= M)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
    //	cout << ans << endl;
  }
}
Problem p02718 (C++) — buggy submission, verdict: Runtime Error

/*
                                                  __          __
      /\\   |   |     /\\   |  | |  |     /\\   | / |  )   /\\   |  )
     /__\\  |   |    /__\\  |--| |  |    /__\\  |<  |-<   /__\\  |-<
    /    \\ |__ |__ /    \\ |  | \\__/   /    \\ | \\ |__) /    \\ |  \\

*/

#import <bits/stdc++.h>
typedef long long ll;
#define forl(n) for (int i = 0; i < n; i++)
#define forll(i, a, b, c) for (int i = a; i < b; i += c)
#define pb(n) push_back(n)

using namespace std;

int main() {
  int m = 0, b, n;
  cin >> n >> b;
  int p[n], x = 0;
  forl(n) {
    cin >> p[i];
    x += p[i];
  }
  if (x % (4 * b) == 0)
    x = x / (4 * b);
  else
    x = (x / (4 * b)) + 1;
  forl(n) {
    if (p[i] >= x) {
      m++;
    }
  }
  if (m >= b) {
    cout << "Yes\\n";
  } else {
    cout << "No\\n";
  }
}


Error: -11

Fixed submission:

#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  cin.tie(0);
  cout.tie(0);
  int n, m, a[1000];
  int sum = 0, s_;
  float t;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    scanf("%d", a[i]);
    s_ += a[i];
  }
  cout << s_ << endl;
  t = 1.0 / (4 * m);
  s_ *= t;
  cout << t << " " << s_ << endl;
  for (int i = 0; i < n; i++) {
    if (a[i] < s_) {
      cout << "No";
      break;
    } else
      sum++;
  }
  if (sum == n)
    cout << "Yes";
  return 0;
}
Problem p02718 (C++) — buggy submission, verdict: Runtime Error

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

int main() {

  double m, n, s = 0.0, c = 0.0, v;
  long long int i;

  cin >> n >> m;
  vector<double> a;
  for (i = 0; i < n; i++) {
    cin >> v;
    a.push_back(v);
    s += v;
  }
  double t = s / (4 * m);
  for (i = 0; i < n; i++) {
    if (a[i] >= t)
      c++;
  }
  if (c >= m)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}


Error: WA

Fixed submission:


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

int main() {

  int i, m, n, s = 0, c = 0, t;
  vector<int> a(n);
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    s += a[i];
  }
  t = (s / (4 * m));
  for (i = 0; i < n; i++) {
    if (a[i] >= t)
      c++;
  }
  if (c >= m)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}
Problem p02718 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
//<<setprecision(30)
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 1000000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<vector<int>>;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  int s = 0;
  rep(i, N) {
    cin >> A.at(i);
    s += A.at(i);
  }
  sort(begin(A), end(A));
  if (A.at(N - M) * 4 * M < s)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
//<<setprecision(30)
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 1000000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<vector<int>>;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  int s = 0;
  rep(i, N) {
    cin >> A.at(i);
    s += A.at(i);
  }
  sort(begin(A), end(A));
  if (A.at(N - M - 1) * 4 * M < s)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}
Problem p02718 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a[n];
  int sum = 0;
  int res = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  float j = (float)sum / (4.0 * m);
  for (int i = 0; i < n; i++) {
    if (a[i] >= j)
      res++;
  }

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


Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> store;
  for (int i = 0; i < n; i++) {
    cin >> store[i];
  }
  int sum = 0;
  for (int i = 0; i < n; i++) {
    sum += store[i];
  }
  sum = sum / (4 * m);
  int count = 0;
  for (int i = 0; i < n; i++) {
    if (store[i] > sum) {
      count++;
    }
  }
  if (count >= m)
    cout << "Yes"
         << "\\n";
  else
    cout << "No"
         << "\\n";
  return 0;
}
Problem p02718 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N, M, a, b;
  b = 0;
  vector<int> A(N);
  a = 0;
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    b += A.at(i);
  }
  for (int i = 0; i < N; i++) {
    if (A.at(i) * 4 * M >= b) {
      a++;
    }
  }
  if (a >= M) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Error: WA

Fixed submission:

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

int main() {
  int N, M, a, b;
  b = 0;
  vector<int> A(N);
  a = 0;
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    b += A.at(i);
  }
  sort(A.begin(), A.end());
  if (A.at(N - M - 1) >= b / (4 * M)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p02718 (C++) — buggy submission, verdict: Runtime Error

/****************************************************
 *   Template for coding contests                    *
 *   Author    :    Sanjeev Sharma                   *
 *   Email     :    thedevelopersanjeev@gmail.com    *
 *****************************************************/
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#pragma GCC target("sse4")
#pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define deb(x) cout << #x << " is " << x << "\\n";
#define int long long
#define mod 1000000007

const double PI = 2 * acos(0.0);
const long long INF = 1e18L + 5;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  double n, m;
  cin >> n >> m;
  vector<double> arr((int)n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr.begin(), arr.end());
  reverse(arr.begin(), arr.end());
  double required = accumulate(arr.begin(), arr.end(), 0.0) / (4.0 * m);
  if (arr[m - 1] < required) {
    cout << "No";
  } else {
    cout << "Yes";
  }
  return 0;
}


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


Fixed submission:

/****************************************************
 *   Template for coding contests                    *
 *   Author    :    Sanjeev Sharma                   *
 *   Email     :    thedevelopersanjeev@gmail.com    *
 *****************************************************/
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#pragma GCC target("sse4")
#pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define deb(x) cout << #x << " is " << x << "\\n";
#define int long long
#define mod 1000000007

const double PI = 2 * acos(0.0);
const long long INF = 1e18L + 5;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int n, m;
  cin >> n >> m;
  vector<int> arr(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr.begin(), arr.end());
  reverse(arr.begin(), arr.end());
  int required = accumulate(arr.begin(), arr.end(), 0) / (4 * m);
  if (arr[m - 1] < required) {
    cout << "No";
  } else {
    cout << "Yes";
  }
  return 0;
}
Problem p02718 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> vote(N);
  for (int i = 0; i < vote.size(); i++) {
    cin >> vote.at(i);
  }
  double sum = 0.0;
  for (int i = 0; i < vote.size(); i++) {
    sum += vote.at(i);
  }
  sort(vote.begin(), vote.end());
  reverse(vote.begin(), vote.end());
  if (vote.at(M - 1) >= sum / (4 * M)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> vote(N);
  for (int i : vote) {
    cin >> vote.at(i);
  }
  int sum = 0;
  for (int i : vote) {
    sum += vote.at(i);
  }
  if (vote.at(M - 1) >= sum / (4 * M)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p02718 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[]) {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  int tv = 0;

  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    tv += a[i];
  }

  int c = 0;
  double min = (double)tv / (double)(4 * m);

  for (auto v : a) {
    if (((double)v - min) >= 0)
      ++c;
    if (c == m) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[]) {
  int n, m;
  cin >> n >> m;
  vector<int> a(m);

  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }

  int c = 0;
  int min = 1 / (4 * m);

  for (auto v : a) {
    if (v >= min)
      ++c;
    if (c == m) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
}
Problem p02718 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N, M;
  int nCnt = 0;
  cin >> N >> M;

  vector<int> nVec(N);
  int sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> nVec[i];
    sum = sum + nVec[i];
  }

  for (int j = 0; j < N; j++) {
    if (nVec[j] * 4 * M >= sum) {
      nCnt++;
    }
  }

  if (nCnt >= M) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Error: -11

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N, M;
  int nCnt = 0;
  cin >> N >> M;

  std::vector<int> nVec;
  int sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> nVec[i];
    sum = sum + nVec[i];
  }

  for (int j = 0; j < N; j++) {
    if (nVec[j] * 4 * M >= sum) {
      nCnt++;
    }
  }

  if (nCnt >= M) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}