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

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

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

  vector<int> A(N);

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

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

  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (A.at(i) >= (float)sum / (4 * M))
      cnt++;
  }

  if (cnt >= M)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Error: 0

Fixed submission:

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

int main(void) {
  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 += A.at(i);
  }

  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (A.at(i) >= sum / (4 * M))
      cnt++;
  }

  if (cnt >= 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, m;
  double sum;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++)
    sum += a.at(i);
  sort(a.begin(), a.end());
  if (a.at(n - m) >= sum / (4 * m))
    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>
using namespace std;

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

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

int main() {
  int N, M;
  cin >> N >> M;
  int i, count = 0;
  vector<int> A(N);
  int sum;
  for (i = 0; i < N; i++) {
    cin >> A[i];
    sum += A[i];
  }
  for (i = 0; i < N; i++) {
    if (A[i] * 4 * M < sum) {
      continue;
    } else {
      count++;
    }
  }
  if (count >= M) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Error: -11

Fixed submission:

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

int main() {
  int N, M;
  cin >> N >> M;
  int i, count = 0;
  vector<int> A;
  int sum;
  for (i = 0; i < N; i++) {
    cin >> A[i];
    sum += A[i];
  }
  for (i = 0; i < N; i++) {
    if (A[i] / sum < 1 / (4 * M)) {
      continue;
    } else {
      count++;
    }
  }
  if (count >= M) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p02718 (C++) — buggy submission, verdict: Runtime Error

/* Akshat Sharma @akshat98 */
#include <bits/stdc++.h>
#include <iostream>
#define IOS ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define ll long long
#define MOD 1000000007
#define MAX 1000000001
#define vi vector<int>
#define vl vector<ll>
#define vpi vector<pair<int, int>>
#define vpl vector<pair<ll, ll>>
#define rep(i, a, b) for (i = a; i < b; i++)
#define reqp(i, a, b) for (i = a; i <= b; i++)
#define ren for (i = 0; i < n; i++)
#define ALL(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
  // #ifndef ONLINE_JUDGE
  // freopen("input_file.txt", "r", stdin);
  // //freopen("output_file.txt", "w", stdout);
  // #endif
  int i, j, k, l, n, test_case, m, r;
  test_case = 1;
  // cin>>test_case;
  while (test_case--) {
    cin >> n >> m;
    vi vec(n);
    int sum = 0;
    ren {
      cin >> vec[i];
      sum += vec[i];
    }
    sort(ALL(vec));
    reverse(ALL(vec));
    // rep(i,0,m){
    // 	sum+=vec[i];
    // }
    if (vec[m - 1] < (int)(ceil(1.0 * sum / (4 * m)))) {
      cout << "No \\n";
    } else
      cout << "Yes \\n";
  }

  return 0;
}

Error: -11

Fixed submission:

/* Akshat Sharma @akshat98 */
#include <bits/stdc++.h>
#include <iostream>
#define IOS ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define ll long long
#define MOD 1000000007
#define MAX 1000000001
#define vi vector<int>
#define vl vector<ll>
#define vpi vector<pair<int, int>>
#define vpl vector<pair<ll, ll>>
#define rep(i, a, b) for (i = a; i < b; i++)
#define reqp(i, a, b) for (i = a; i <= b; i++)
#define ren for (i = 0; i < n; i++)
#define ALL(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
#ifndef ONLINE_JUDGE
  freopen("input_file.txt", "r", stdin);
// freopen("output_file.txt", "w", stdout);
#endif
  int i, j, k, l, n, test_case, m, r;
  test_case = 1;
  // cin>>test_case;
  while (test_case--) {
    cin >> n >> m;
    vi vec(n);
    int sum = 0;
    ren {
      cin >> vec[i];
      // sum+=vec[i];
    }
    sort(ALL(vec));
    reverse(ALL(vec));
    rep(i, 0, m) { sum += vec[i]; }
    if (vec[m - 1] < (sum / (4 * m))) {
      cout << "No\\n";
    } else
      cout << "Yes\\n";
  }

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

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

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


Error: 0

Fixed submission:

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> votes(N);
  for (int i = 0; i < N; i++) {
    cin >> votes[i];
  }
  sort(votes.begin(), votes.end());
  reverse(votes.begin(), votes.end());
  int sum = 0;
  for (int i = 0; i < N; i++) {
    sum += votes[i];
  }
  if (votes[M] >= 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;
// useful library
int long long gcd(int long long a, int long long b) {
  return b ? gcd(b, a % b) : a;
} // 最大公約数
int long long lcm(int long long a, int long long b) {
  return a / gcd(a, b) * b;
} // 最小公倍数
int long long GetDigit(int long long num) {
  int long long digit = 0;
  while (num != 0) {
    num /= 10;
    digit++;
  }
  return digit;
} // 桁数
int long long GetDigitN(int long long num, int long long N) {
  int long long digit = 0;
  while (num != 0) {
    num /= N;
    digit++;
  }
  return digit;
} // 十進数でnumの際のN進数における桁数

int main() {
  bool B = false;
  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  int long long D = 0;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    D = D + A.at(i);
  }
  sort(A.begin(), A.end(), greater<int>());
  double C = D / floor(4 * M);
  if (A.at(M - 1) >= C) {
    B = true;
  }
  if (B == true) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

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;
// useful library
int long long gcd(int long long a, int long long b) {
  return b ? gcd(b, a % b) : a;
} // 最大公約数
int long long lcm(int long long a, int long long b) {
  return a / gcd(a, b) * b;
} // 最小公倍数
int long long GetDigit(int long long num) {
  int long long digit = 0;
  while (num != 0) {
    num /= 10;
    digit++;
  }
  return digit;
} // 桁数
int long long GetDigitN(int long long num, int long long N) {
  int long long digit = 0;
  while (num != 0) {
    num /= N;
    digit++;
  }
  return digit;
} // 十進数でnumの際のN進数における桁数

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

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < (n); ++i)
#define ALL(n) begin(n), end(n)
using ll = long long;
const ll INF = numeric_limits<long long>::max();

int main() {
  int N, M;
  vector<int> A(N);
  cin >> N >> M;
  REP(i, 0, N) cin >> A[i];

  int sum = 0;
  REP(i, 0, N) sum += A[i];

  int cnt = 0;
  REP(i, 0, N) {
    if (A[i] >= (float)sum / 4 / M) {
      cnt++;
    }
  }

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

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < (n); ++i)
#define ALL(n) begin(n), end(n)
using ll = long long;
const ll INF = numeric_limits<long long>::max();

int main() {
  int N, M;
  vector<int> A(N);
  cin >> N >> M;
  REP(i, 0, N) cin >> A[i];

  int sum = 0;
  REP(i, 0, N) sum += A[i];

  int cnt = 0;
  REP(i, 0, N) {
    if (A[i] >= sum / 4 / M) {
      cnt++;
    }
  }

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

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

#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

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(), greater<int>());
  int sum = accumulate(a.begin(), a.end(), 0);
  double percentage = static_cast<double>(sum) / (4 * static_cast<double>(m));

  if (a.at(m - 1) >= percentage) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

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(), greater<int>());
  int sum = accumulate(a.begin(), a.end(), 0);

  bool flag = true;
  for (int i = 0; i <= m; i++) {
    int percentage = sum / (4 * m);
    if (a.at(i) <= percentage)
      flag = false;
  }

  if (flag) {
    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 M, N;
  cin >> N >> M;
  vector<int> data(N);
  for (int i = 0; i < N; i++) {
    cin >> data.at(i);
  }
  sort(data.begin(), data.end());
  reverse(data.begin(), data.end());
  int sum = 0;
  for (int i = 0; i < N; i++) {
    sum += data.at(i);
  }

  if (data.at(M - 1) * 4 * M < sum) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}


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


Fixed submission:

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

int main() {
  int M, N;
  cin >> M >> N;
  vector<int> data(N);
  for (int i = 0; i < N; i++) {
    cin >> data.at(i);
  }
  sort(data.begin(), data.end());
  reverse(data.begin(), data.end());
  int sum = 0;
  for (int i = 0; i < N; i++) {
    sum += data.at(i);
  }

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

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

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int t = 1;
  while (t--) {
    int count, m;
    cin >> count >> m;

    vector<int> nish;
    long long int total = 0;
    for (int i = 0; i < count; i++) {
      int first;
      cin >> first;
      total += first;
      nish.push_back(first);
    }
    sort(nish.rbegin(), nish.rend());
    int temp = total % (4 * m) == 0 ? total / (4 * m) : total / (4 * m) + 1;
    int flag = 0;
    for (int i = 0; i < count; i++) {
      // cout<<nish[i]<<" "<<temp;
      if (nish[i] >= temp)
        m--;
      if (m > 0 && nish[i] < temp) {
        flag = 1;
        break;
      }
      if (m == 0)
        break;
    }
    if (flag)
      cout << "No" << endl;
    else
      cout << "Yes" << endl;

    // cot<<c<<" "<<a<<" "<<b<<endl;
  }

  return 0;
}

Error: WA

Fixed submission:

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

int 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 t = 1;
  while (t--) {
    int count, m;
    cin >> count >> m;

    vector<int> nish;
    long long int total = 0;
    for (int i = 0; i < count; i++) {
      int first;
      cin >> first;
      total += first;
      nish.push_back(first);
    }
    sort(nish.rbegin(), nish.rend());
    int temp = total / (4 * m);
    int flag = 0;
    for (int i = 0; i < count; i++) {
      // cout<<nish[i]<<" "<<temp;
      if (nish[i] >= temp)
        m--;
      if (m > 0 && nish[i] < temp) {
        flag = 1;
        break;
      }
      if (m == 0)
        break;
    }
    if (flag)
      cout << "No" << endl;
    else
      cout << "Yes" << endl;

    // cot<<c<<" "<<a<<" "<<b<<endl;
  }

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

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

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

Error: 0

Fixed submission:

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

int main() {
  int n, m;
  int ans = 0, total_bid = 0;
  vector<int> a(n);

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

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

int main() {

  int N, M;
  cin >> N >> M;
  int sum = 0;

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

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

  if (sum * 1.0 / (4 * M) > A.at(M - 1)) {
    cout << "No" << endl;
  }

  else {
    cout << "Yes" << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

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

int main() {

  int N, M;
  cin >> N >> M;
  int sum = 0;

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

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

  if (sum / (4 * M) <= A.at(N - M - 1)) {
    cout << "Yes" << endl;
  }

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

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

int main() {
  int N, M;
  cin >> N >> M;
  int a[N];
  for (int i = 0; i < N; i++)
    cin >> a[i];
  int sum = 0;
  for (int i = 0; i < N; i++) {
    sum += a[i];
  }
  sort(a, a + N, greater<>());
  if (a[M - 1] * 4 * M >= sum) {
    cout << "Yes";
  } else {
    cout << "No";
  }
}


Error: -8

Fixed submission:

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

int main() {
  int N, M;
  int a[100];
  for (int i = 0; i < 100; i++)
    cin >> a[i];
  int sum = 0;
  for (int i = 0; i < N; i++) {
    sum += a[i];
  }
  sort(a, a + N, greater<>());
  if (a[M - 1] > sum / (4 * M)) {
    cout << "Yes";
  } else {
    cout << "No";
  }
}
Problem p02718 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n, m;
  int c = 0, i = 0, all = 0;

  scanf("%d %d", &n, &m);

  vector<int> vec(n);
  for (i = 0; i < n; i++) {
    cin >> vec.at(i);
    all += vec.at(i);
  }
  i = 0;
  for (i = 0; i < n && c < m; i++) {
    if (all <= vec.at(i) * m * 4)
      c += 1;
  }
  if (c >= m)
    printf("Yes");
  else
    printf("No");
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, m;
  int c = 0, i = 0, all = 0;

  scanf("%d %d", &n, &m);

  vector<int> vec(n);
  for (i = 0; i < n; i++) {
    cin >> vec.at(i);
    all += vec.at(i);
  }
  i = 0;
  while (i < n) {
    if (n * 4 / all <= vec.at(i))
      c += 1;
  }
  if (c >= m)
    printf("Yes");
  else
    printf("No");
  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> a(n);
  int total = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    total += a[i];
  }

  string res;
  int count = 0;
  for (int i = 0; i < n; ++i)
    if (a[i] >= float(total) / (4 * m))
      ++count;
  if (count >= m)
    res = "Yes";
  else
    res = "No";

  cout << res;
  return 0;
}

Error: WA

Fixed submission:



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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  int total = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    total += a[i];
  }

  string res;
  if (a[m] > total / (4 * a[m]))
    res = "Yes";
  else
    res = "No";

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

#include <bits/stdc++.h>

using namespace std;
#define ll long long

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  int sum = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    sum += a[i];
  }
  int minVotes = ceil(sum / (4.0 * m));
  int count = 0;

  for (auto i : a)
    if (i >= minVotes)
      count += 1;

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

  return 0;
}

Error: 1

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
#define ll long long

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < n; ++i)
    cin >> a[i];

  int minVotes = 1 / (4 * m);
  int count = 0;
  for (auto i : a) {
    if (i >= minVotes)
      count++;
    if (count >= m) {
      cout << "Yes";
      return 1;
    }
  }

  cout << "No";
  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> a(n);
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    sum += a.at(i);
  }
  sort(a.begin(), a.end());
  if (a.at(n - m) * 4 * m >= sum) {
    cout << "Yes" << endl;
    return 0;
  } else {
    cout << "No" << endl;
    return 0;
  }
}


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());
  int sum = 0;
  for (int i : a) {
    sum += i;
  }
  if (a.at(m) >= sum / (4 * m)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p02718 (C++) — buggy submission, verdict: Runtime Error

/**
 *   Author:    @glaucoacassioc
 *   Created on 11.09.2020, 15:32:16
 **/
#include <bits/stdc++.h>
#define INF 1000000000
using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
vector<vii> AdjList;

vi pai, color, dist, ts;

int main() {
  //	freopen("in.txt","r", stdin);
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, ans, sum = 0, cont = 0;

  cin >> n >> m;
  vi v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    sum += v[i];
  }
  ans = 4 * m;
  bool popular = false;
  for (int i = 0; i < n; i++) {
    if (1LL * v[i] * ans >= sum)
      cont++;
    if (cont == m) {
      popular = true;
      break;
    }
  }
  popular ? cout << "Yes\\n" : cout << "No\\n";

  return 0;
}

Error: WA

Fixed submission:

/**
 *   Author:    @glaucoacassioc
 *   Created on 11.09.2020, 15:32:16
 **/
#include <bits/stdc++.h>
#define INF 1000000000
using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
vector<vii> AdjList;

vi pai, color, dist, ts;

int main() {
  freopen("in.txt", "r", stdin);
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, ans, sum = 0, cont = 0;

  cin >> n >> m;
  vi v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    sum += v[i];
  }
  ans = sum / (4 * m);
  bool popular = false;
  for (int i = 0; i < n; i++) {
    if (v[i] >= ans)
      cont++;
    if (cont == m)
      popular = true;
  }
  popular ? cout << "Yes\\n" : cout << "No\\n";

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

#include <bits/stdc++.h>
#define ll long long
#define loop(n) for (ll i = 0; i < n; i++)
#define sort(a) sort(a.rbegin(), a.rend())
using namespace std;

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

  int n, m, x, votes = 0;
  cin >> n >> m;
  vector<int> vote(n); // 1votes, 2id
  for (int i = 0; i < n; i++) {
    cin >> vote[i];
    votes += vote[i];
  }
  float thresh = votes / (4.0 * m);
  int count = 0;
  for (int i = 0; i < n; i++) {
    if (vote[i] >= thresh)
      count++;
  }
  cout << (count >= m ? "Yes\\n" : "No\\n");
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define loop(n) for (ll i = 0; i < n; i++)
#define sort(a) sort(a.rbegin(), a.rend())
using namespace std;

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

  int n, m, votes = 0;
  cin >> n >> m;
  vector<pair<int, int>> ma(4); // 1votes, 2id
  for (int i = 0; i < n; i++) {
    ma[i].second = i + 1;
    cin >> ma[i].first;
    votes += ma[i].first;
  }
  sort(ma);
  votes = votes / (4 * m);
  int count = 0;
  for (int i = 0; i < n; i++) {
    if (ma[i].first >= votes)
      count++;
  }
  cout << (count >= m ? "Yes\\n" : "No\\n");
  return 0;
}
Problem p02718 (C++) — buggy submission, verdict: Runtime Error

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

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

  vector<int> a(n);
  int sum = 0;
  rep(i, n) {
    cin >> a[i];
    sum += a[i];
  }
  int count = 0;
  rep(i, n) {
    if (a[i] * (4 * m) >= sum) {
      count++;
    }
  }
  if (count >= m) {
    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 0) >= this->size() (which is 0)


Fixed submission:

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a;
  rep(i, n) { cin >> a.at(i); }

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

  int sum = 0;

  rep(i, n) { sum += a.at(i); }

  int z = sum / (4 * m);

  if (a.at(m) >= z)
    cout << "Yes" << endl;

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