alexjercan/bugnet huggingface dataset:
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;
using ll = long long;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int s = 0;
  rep(i, n) s += a[i];
  int ans = 0;
  rep(i, n) {
    if (a[i] * (4 * m) >= s)
      ans++;
  }
  if (ans >= m) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int n, m, s = 0, ans = 0;
  vector<int> a(n);
  cin >> n >> m;
  rep(i, n) cin >> a[i];
  rep(i, n) s += a[i];
  rep(i, n) {
    if (a[i] * (4 - m) >= s)
      ans++;
  }
  if (ans >= 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;

int main() {
  int N;
  int M;
  int count = 0;
  int sum = 0;

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

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

  for (int i = 0; i < N; i++) {
    if (sum <= A.at(i) * 4 * M) {
      count++;
    }
  }
  if (count >= M) {
    cout << "Yes" << endl;

  } else {
    cout << "No" << endl;
  }
}

Error: 0

Fixed submission:

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

int main() {
  int N;
  int M;
  vector<int> A(N);
  int count = 0;
  int sum = 0;

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

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

  for (int i = 0; i < N; i++) {
    if (sum <= A.at(i) * 4 * M) {
      count++;
    }
  }
  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;
int main() {
  int N, M;
  vector<int> A(N);
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  int sum = 0;
  for (int i = 0; i < N; i++) {
    sum = sum + A.at(i);
  }
  int Ave;
  if (sum % (4 * M) == 0) {
    Ave = sum / (4 * M);
  } else {
    Ave = sum / (4 * M) + 1;
  }
  int count;
  for (int i = 0; i < N; i++) {
    if (A.at(i) >= Ave) {
      count++;
    } else {
      count = count;
    }
  }
  if (count >= 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;
int main() {
  int N, M;
  vector<int> A(N);
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  for (int i = 0; i < M; i++) {
    if (A[i] >= N / (4 * M) + 1) {
      continue;
    } else {
      cout << "No" << endl;
      break;
    }
    cout << "Yes" << endl;
  }
}
Problem p02718 (C++) — buggy submission, verdict: Runtime Error

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

int main() {

  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  int n, m, sum = 0;
  cin >> n >> m;

  vector<int> v(n);

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

  int count = 0;

  for (int i = 0; i < n; i++) {

    if (v[i] >= sum / (4 * (double)m))
      count++;
  }

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

  return 0;
}


Error: -8

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;

  int arr[n];

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

  long long int sum = 0;

  for (int i = 0; i < n; i++) {
    sum += arr[i];
  }

  int counter = 0;
  for (int i = 0; i < n; i++) {
    if (arr[i] >= sum / (4 * m))
      m--;
  }

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

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

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

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


Error: 0

Fixed submission:

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

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

/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java,
PHP, Ruby, Perl, C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly,
HTML, CSS, JS, SQLite, Prolog. Code, Compile, Run and Debug online from anywhere
in world.

*******************************************************************************/
#include <iostream>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a[n];
  long int votes = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    votes += a[i];
  }
  int m1 = 0;
  float perc = votes / float(4 * m);
  for (int i = 0; i < n; i++) {
    if (a[i] >= perc) {
      m--;
    }
    if (m == 0) {
      m1 = 1;
      break;
    }
  }
  if (m1) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  return 0;
}


Error: 1

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
  int N, M = 1, 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 <bits/stdc++.h>
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;

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

  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());

  long sum = 0;

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

  if (4 * M * A.at(M - 1) >= sum)
    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> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }

  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());

  long sum = 0;

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

  if (A.at(M - 1) < sum / (4 * M))
    cout << "No" << endl;
  if (A.at(M - 1) == A.at(M))
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}
Problem p02718 (C++) — buggy submission, verdict: Runtime Error

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

#define ll long long int
#define pi pair<ll, ll>

void solve() {
  int n, m;
  cin >> n >> m;
  int ans = 0;
  vector<ll> v(n);
  for (int i = 0; i < n; i += 1) {
    cin >> v[i];
  }

  ll sum = accumulate(v.begin(), v.end(), 0LL);
  for (int i = 0; i < n; i += 1) {
    if (v[i] * 4 * m >= sum)
      ans += 1;
  }

  if (ans >= m)
    cout << "Yes\\n";
  else
    cout << "No\\n";
}

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

  int test = 1;
  // cin >> test;
  while (test--)
    solve();
  return 0;
}

Error: 0

Fixed submission:

//=====================COMPILER OPTIMIZATION STARTS=======================
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
//======================COMPILER OPTIMIZATION ENDS=======================

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

#define ll long long int
#define pi pair<ll, ll>

ll power(ll x, ll y, ll mod = 1e9 + 7) {
  ll res = 1;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % mod;
    y = y >> 1;
    x = (x * x) % mod;
  }
  return res % mod;
}

void solve() {
  int n, m;
  cin >> n >> m;
  int ans = 0;
  vector<ll> v(n);
  for (int i = 0; i < n; i += 1) {
    cin >> v[i];
  }

  ll sum = accumulate(v.begin(), v.end(), 0LL);
  for (int i = 0; i < n; i += 1) {
    if (v[i] * 4 * m >= sum)
      ans += 1;
  }

  if (ans >= m)
    cout << "Yes\\n";
  else
    cout << "No\\n";
}

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

  int test = 1;
  // cin >> test;
  while (test--)
    solve();
  return 0;
}
Problem p02718 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, m;
  int c = 0;
  int sum = 0;
  int i;
  float vote;

  cin >> n >> m;
  int a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < n; i++) {
    sum += a[i];
  }
  for (i = 0; i < n; i++) {
    if (a[i] * (4 * m) >= sum) {
      c++;
    }
  }
  if (c >= m)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int n, m;
  int a[n];
  int c = 0;
  int sum = 0;
  int i;

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ull unsigned long long
#define rep(n) for (ll i = 0; i < n; i++)
#define rep2(n) for (ll j = 0; j < n; ++j)
#define repd(n) for (ll i = n - 1; i >= 0; i--)
#define MOD 1000000007
#define pii pair<ll, ll>
#define vll vector<ll>
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define nl "\\n"
#define INF 0x3f3f3f3f
#define sz(a) a.size()
#define all(a) a.begin(), a.end()
#define M 998244353
#define limit 100000000

int main() {

  int n, m;
  cin >> n >> m;
  int s = 0;
  int a[n];
  for (int i = 0; i < n; ++i)
    cin >> a[i], s += a[i];
  int c = 0;
  for (int i = 0; i < n; ++i)
    if (a[i] * 4 * m >= s)
      ++c;
  if (c >= m)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ull unsigned long long
#define rep(n) for (ll i = 0; i < n; i++)
#define rep2(n) for (ll j = 0; j < n; ++j)
#define repd(n) for (ll i = n - 1; i >= 0; i--)
#define MOD 1000000007
#define pii pair<ll, ll>
#define vll vector<ll>
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define nl "\\n"
#define INF 0x3f3f3f3f
#define sz(a) a.size()
#define all(a) a.begin(), a.end()
#define M 998244353
#define limit 100000000

void solve() {
  ll n, m;
  cin >> n >> m;
  ll a[n];
  rep(n) cin >> a[i];
  ll s = 0;
  rep(n) s += a[i];
  ll c = 0;
  rep(n) if (a[i] >= s / (4 * m))++ c;
  if (c >= m)
    cout << "Yes";
  else
    cout << "No";
}

int main() {

  fast;
  ll t = 1;
  // cin>>t;
  rep(t) { solve(); }
  return 0;
}
Problem p02718 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, m;
  vector<int> a;
  int k;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> k;
    a.push_back(k);
  }
  sort(a.begin(), a.end(), std::greater<int>());
  int sum = 0;
  for (int x : a) {
    sum += x;
  }
  if (a[m - 1] * (4 * m) >= sum) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, m;
  vector<int> a;
  int k;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> k;
    a.push_back(k);
  }
  sort(a.begin(), a.end(), std::greater<int>());
  int sum = 0;
  for (int x : a) {
    sum += x;
  }
  for (int i = 0; i < m; i++) {
    if ((float)a[i] - (float)(sum / (4 * m)) < 0) {
      cout << "No";
      return -1;
    }
  }
  cout << "Yes";
  return 0;
}
Problem p02718 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define eps 1e-9
#define MOD 1000000007;
#define INV_10 299473306;
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  double m;
  cin >> n >> m;
  double a[n], sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  sort(a, a + n);
  reverse(a, a + n);
  double nb = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] >= sum / (4 * m))
      nb++;
  }
  if (nb >= m)
    cout << "Yes\\n";
  else
    cout << "No\\n";
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define eps 1e-9
#define MOD 1000000007;
#define INV_10 299473306;
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  int n;
  double m;
  cin >> n >> m;
  double a[n], sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  sort(a, a + n);
  reverse(a, a + n);
  double nb = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] >= sum / (4 * m))
      nb++;
  }
  if (nb >= m)
    cout << "Yes\\n";
  else
    cout << "No\\n";
}
Problem p02718 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N, M;
  int S = 0;
  cin >> N >> M;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    S += A.at(i);
  }

  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  if (S % (4 * M) == 0) {
    if (A.at(M - 1) >= S / (4 * M))
      cout << "Yes";

    else
      cout << "No";
  } else {
    if (A.at(M - 1) > S / (4 * M))
      cout << "Yes";

    else
      cout << "No";
  }
}


Error: WA

Fixed submission:

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

int main() {
  int N, M;
  int S = 0;
  cin >> N >> M;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    S += A.at(i);
  }

  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  if (A.at(M) >= S / (4 * M))
    cout << "Yes";

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, cnt = 0, flag = 0;
  double sum = 0;
  cin >> n >> m;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  double chk = sum * ((double)1 / (4 * m));
  for (int i = 0; i < n; i++) {
    if (a[i] >= chk) {
      cnt++;
      if (cnt == m) {
        flag = 1;
        break;
      }
    }
  }
  // cout<<chk;
  if (flag)
    cout << "Yes\\n";
  else
    cout << "No\\n";
}


Error: 1

Fixed submission:

#include <bits/stdc++.h>

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 <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, a, b) for (int i = a; i < b; i++)
typedef long long ll;
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  int sum = 0;
  rep(i, n) {
    cin >> a.at(i);
    sum += a.at(i);
  }
  sort(a.begin(), a.end(), greater<int>());
  double h = sum / (4 * (double)m);
  cerr << h << endl;
  string b = "Yes";
  rep(i, m) {
    if (a.at(i) < h)
      b = "No";
  }
  cout << b << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  int sum = 0;
  rep(i, n) {
    cin >> a.at(i);
    sum += a.at(i);
  }
  sort(a.begin(), a.end(), greater<int>());
  sum /= 4 * m;
  string b = "Yes";
  if (a.at(m) <= sum)
    b = "No";
  cout << b << endl;
}
Problem p02718 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <string>
#include <vector>

using namespace std;

int main() {
  float n, m;
  cin >> n >> m;
  float sum = 0;
  vector<int> vc(n);
  for (int i = 0; i < n; i++) {
    cin >> vc.at(i);
    sum += vc.at(i);
  }
  sort(vc.begin(), vc.end(), greater<int>());

  string ans;
  float num = sum / (4 * m);
  if (vc[m - 1] >= num) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n, m;
  vector<int> vc(n);
  cin >> n >> m;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> vc.at(i);
    sum += vc.at(i);
  }
  sort(vc.begin(), vc.end(), greater<int>());

  string ans = "Yes";
  if (vc[m - 1] <= sum / (4 * m)) {
    ans = "No";
  }

  cout << ans << endl;
}
Problem p02718 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int main(void) {
  int m, n;
  int a[1000];
  int i, sum = 0;
  int flag = 0;

  do {
    scanf("%d %d", &n, &m);
  } while ((n < 1 || n > 100) || ((m < 1 || m > 100) || m > n));

  for (i = 1; n >= i; i++) {
    do {
      scanf("%d ", &a[i]);
    } while (a[i] < 1 || a[i] > 1000);
    sum += a[i];
  }
  for (i = 1; n >= i; i++)
    if (a[i] * (4 * m) >= sum)
      flag++;

  if (m <= flag)
    puts("Yes");
  else
    puts("No");

  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int main(void) {
  int m, n;
  int a[1000];
  int i, sum = 0;
  int flag = 0;

  do {
    scanf("%d %d", &n, &m);
  } while ((n < 1 || n > 100) || ((m < 1 || m > 100) || m > n));

  for (i = 0; n >= i; ++i) {
    do {
      scanf("%d ", &a[i]);
    } while (a[i] < 1 || a[i] > 1000);
    sum += a[i];
  }
  for (i = 1; n >= i; i++)
    if (a[i] >= sum / (4 * m))
      flag++;

  if (m <= flag)
    puts("Yes");
  else
    puts("No");

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

#include <algorithm>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main() {
  int N, M;
  double sum = 0;
  int A[100];
  rep(i, 100) { A[i] = 0; }

  cin >> N >> M;
  rep(i, N) {
    cin >> A[i];
    sum += A[i];
  }
  std::sort(A, A + 100, std::greater<>());

  if ((int)sum % (4 * M) == 0) {
    int tmp = (int)sum % (4 * M);
    if (A[M - 1] == tmp) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  if (double(A[M - 1]) < sum / 4.0 / M) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main() {
  int N, M;
  double sum = 0;
  vector<int> A(N);

  cin >> N >> M;
  rep(i, N) {
    cin >> A[i];
    sum += A[i];
  }
  std::sort(A.begin(), A.end(), std::greater<int>());
  if (double(A[M - 1]) < sum / 4 / M) {
    cout << "No" << endl;
  } else {
    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)
#define printInt(a) printf("%d\\n", a)
#define printll(a) printf("%lld\\n", a)
#define scanll(a) scanf("%lld", &a)
#define scanInt(a) scanf("%d", &a)
#define scan2Int(a, b) scanf("%d %d", &a, &b)
#define scan3Int(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define scan4Int(a, b, c, d) scanf("%d %d %d %d", &a, &b, &c, &d)
typedef long long ll;
using namespace std;

int main() {
  int n, m, total = 0;
  scan2Int(n, m);
  int as[n];
  rep(i, n) {
    cin >> as[i];
    total += as[i];
  }
  double border = (double)total / (4 * m);
  rep(i, n) {
    if (as[i] >= border)
      m -= 1;
    if (m <= 0)
      break;
  }
  if (m <= 0)
    printf("Yes\\n");
  else
    printf("No\\n");
  return 0;
}


Error: WA

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int x, y, i, j, sum = 0, arr[x];
  cin >> x >> y;

  for (i = 0; i < x; i++) {
    cin >> arr[i];
    sum += arr[i];
  }
  double t = (double)sum / (4 * y);

  for (j = 0; j < x; j++) {
    if (arr[j] >= t)
      y -= 1;
    if (y <= 0)
      break;
  }
  if (y <= 0)
    cout << "yes";
  else
    cout << "no";
  return 0;
}
Problem p02718 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, m, a[1000], c = 0, all = 0;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    all += a[i];
  }
  for (int i = 0; i < n; i++) {
    if (a[i] >= all / (4.0 * m))
      c++;
  }
  if (c >= m)
    cout << "Yes";
  else
    cout << "No";
}

Error: -8

Fixed submission:

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

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

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define repr(i, a, b) for (int i = a; i >= b; i--)
#define ll long long int
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<double> a(n);
  int sum = 0;
  rep(i, 0, n - 1) {
    cin >> a[i];
    sum += a[i];
  }
  sort(a.begin(), a.end());
  double k = ((double)sum / (4 * m));
  int c = 0;
  int i = a.size() - 1;
  while (i >= 0) {
    if (a[i] >= k) {
      i--;
      c++;
    } else {
      break;
    }
  }
  if (c >= m)
    cout << "Yes\\n";
  else
    cout << "No\\n";
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define repr(i, a, b) for (int i = a; i >= b; i--)
#define ll long long int
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  int sum = 0;
  rep(i, 0, n - 1) {
    cin >> a[i];
    sum += a[i];
  }
  sort(a.begin(), a.end());
  int k = sum / (4 * m);
  int c = 0;
  int i = a.size() - 1;
  while (i >= 0) {
    if (a[i] >= k) {
      i--;
      c++;
    } else {
      break;
    }
  }
  if (c >= m)
    cout << "Yes\\n";
  else
    cout << "No\\n";
  return 0;
}