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

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

int main() {
  int n, m, sum = 0;
  cin >> n >> m;
  int a[n + 1];
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  sort(a + 1, a + 1 + n);
  int x = sum / (4 * m);
  int f = 0;
  if (x * m * 4 == sum)
    f = 1;
  bool f1 = true;
  // cout << "lol" << endl;
  for (int i = n; i > (n - m); i--) {
    if (a[i] > x)
      continue;
    if (a[i] == x && f == 1)
      continue;
    f1 = false;
  }
  cout << ((f1 == false) ? ("No") : ("Yes")) << endl;
  return 0;
}


Error: -11

Fixed submission:

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

int main() {
  int n, m, sum = 0;
  cin >> n >> m;
  int a[n + 1];
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  sort(a + 1, a + 1 + n);
  int x = sum / (4 * m);
  int f = 0;
  if (x * m * 4 == sum)
    f = 1;
  bool f1 = true;
  for (int i = n; i > (n - m); i++) {
    if (a[i] > x)
      continue;
    if (a[i] == x && f == 1)
      continue;
    f1 = false;
  }
  cout << ((f1 == false) ? ("No") : ("Yes")) << endl;
  return 0;
}
Problem p02718 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

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

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

  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] >= ((double)sum / (4 * m))) {
      cnt++;
    }
  }

  if (cnt >= 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;
  cin >> N >> M;
  int hyou = 0;
  vector<int> A;
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
    hyou += A[i];
  }

  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  hyou /= 4;
  for (int i = 1; i <= M; i++) {
    if (A[i] >= hyou) {
    } else {
      cout << "No" << endl;
      break;
    }
  }

  cout << "Yes" << endl;

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

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

int main() {
  int N, M;
  vector<int> A(N);
  int soutoku = 0;
  int hantei = 0;

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

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

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

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

  for (int i = 0; i < M; i++) {
    if (A.at(i) >= (double)soutoku / (4 * M)) {
      hantei++;
    }
  }

  if (hantei < M) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}

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;

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

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

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

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

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

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

#include <stdio.h>

int main() {
  int n, m, i;
  int sum = 0;
  int re = 0;

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

  int a[n];

  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    sum = sum + a[i];
  }

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

  if (re >= m)
    printf("Yes");
  else
    printf("No");

  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>

int main() {
  int n, m, i;
  int sum = 0;
  int re = 0;

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

  int a[n];

  for (i = 0; i < n; i++) {
    scanf("%d", a[i]);
    sum = sum + a[i];
  }

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

  if (re >= 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;
  double sum = 0;
  cin >> n >> m;
  vector<int> ninki(n);
  for (int i = 0; i < n; i++) {
    int num;
    cin >> num;
    sum += num;
    ninki.at(i) = num;
  }
  stable_sort(ninki.begin(), ninki.end());
  if (ninki.at(n - m) < sum / (4 * m)) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
}


Error: 0

Fixed submission:

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

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

#include <bits/stdc++.h>
#include <stdio.h>
#include <stdlib.h>
int compare_int(const void *a, const void *b) { return *(int *)a - *(int *)b; }

using namespace std;

int main() {
  int N, M;
  int sum = 0;
  int c = 0;
  double D;
  cin >> N >> M;
  int A[N];

  for (int a = 0; a < N; a++) {
    cin >> A[a];
    sum += A[a];
  }

  qsort(A, N, sizeof(int), compare_int);

  D = sum / (4.0 * M);

  for (int b = N; b >= 0; b--) {

    if (D <= A[b - 1]) {
      c++;
    } else {
      break;
    }
  }
  if (c >= 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>
#include <stdio.h>
#include <stdlib.h>
int compare_int(const void *a, const void *b) { return *(int *)a - *(int *)b; }

using namespace std;

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

  for (int a = 1; a < N + 1; a++) {
    cin >> A.at(a);
    sum += A.at(a);
  }

  if (sum / (4 * M) < A.at(M)) {
    cout << "Yes" << endl;
    return 0;
  } else {
    cout << "No" << 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;
using ll = long long;
using P = pair<int, int>;

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 cnt = 0;
  rep(i, n) {
    if (a[i] * (4 * m) >= s)
      cnt++;
  }
  // cnt: count
  if (cnt >= m) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
};

Error: -11

Fixed submission:

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

int main() {
  int n, m;
  vector<int> a;
  cin >> n >> m;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int j = 0; j < a.size(); ++j) {
    int total = 0;
    total += a[j];
    if (a[j] >= total * (1 / (4 * m)))
      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, m, sum = 0, wyn = 0;
  cin >> n >> m;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    int foo;
    cin >> foo;
    sum += foo;
    v.push_back(foo);
  }
  for (auto x : v) {
    if (x >= int(ceil(double(sum + 0.0) / double(4 * m + 0.0))))
      wyn++;
  }
  if (wyn >= m)
    cout << "Yes";
  else
    cout << "No";

  return 0;
}

Error: 0

Fixed submission:

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

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

#define fastio                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cin.exceptions(cin.failbit);
// #define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) >
// (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define rep(i, a, b) for (lli i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) lli((x).size())
#define what_is(x) cerr << #x << " is " << x << endl;
#define wis cout << endl << "I already speak english, bitch" << endl << endl;

typedef long long int lli;
typedef vector<lli> vi;
typedef pair<lli, lli> ii;
typedef vector<ii> vii;
typedef pair<ii, lli> iii;
typedef long double C;

#define trace(args...)                                                         \\
  {                                                                            \\
    string _s = #args;                                                         \\
    replace(_s.begin(), _s.end(), ',', ' ');                                   \\
    stringstream _ss(_s);                                                      \\
    istream_iterator<string> _it(_ss);                                         \\
    err(_it, args);                                                            \\
  }
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cout << *it << " : " << a << endl;
  err(++it, args...);
}

int main() {
  int n, m, s = 0;
  cin >> n >> m;
  vi v;
  rep(i, 0, n) {
    int foo;
    cin >> foo;
    s += foo;
    v.pb(foo);
  }
  int wyn = 0;
  for (auto x : v) {
    if ((s / (4 * m)) == 0)
      continue;
    if (x >= (s / (4 * m)))
      wyn++;
  }
  if (wyn >= m)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

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

#include <iostream>
#include <sstream>
using namespace std;
#include <algorithm>
#include <bits/stdc++.h>
#include <iterator>
#include <utility>
#define go return 0
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep(j, n) for (int j = 0; j < n; ++j)
#define REP(i, n) for (int i = 1; i <= n; ++i)
#define all(v) ((v).begin()), ((v).end())
#define len(s) ((int)s.size())
#define F first
#define S second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef double db;
typedef vector<int> ve;
typedef vector<vector<int>> vee;
typedef vector<pair<ll, ll>> vepa;
typedef set<int> se;
typedef map<int, int> mpp;
const ll N = 1e5 + 5;
ll arr[N], A[N], ARR[N];
bool visited[N] = {};
ll cnt[N], freq[N];
bool f, ff;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll n, m, sum = 0, count(0);
  cin >> n >> m;
  rep(i, n && cin >> arr[i]) { sum += arr[i]; }
  rep(i, n) {
    if (arr[i] * 4 * m >= sum)
      count++;
  }
  if (count >= m)
    puts("Yes");
  else
    puts("No");
  go;
}


Error: 4

Fixed submission:

#include <iostream>
#include <sstream>
using namespace std;
#include <algorithm>
#include <bits/stdc++.h>
#include <iterator>
#include <utility>
#define go return 0
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep(j, n) for (int j = 0; j < n; ++j)
#define REP(i, n) for (int i = 1; i <= n; ++i)
#define all(v) ((v).begin()), ((v).end())
#define len(s) ((int)s.size())
#define F first
#define S second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef double db;
typedef vector<int> ve;
typedef vector<vector<int>> vee;
typedef vector<pair<ll, ll>> vepa;
typedef set<int> se;
typedef map<int, int> mpp;
const ll N = 1e5 + 5;
ll arr[N], A[N], ARR[N];
bool visited[N] = {};
ll cnt[N], freq[N];
bool f, ff;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll n, m, sum = 0, count(0);
  cin >> n >> m;
  rep(i, n && cin >> arr[i]) { sum += arr[i]; }
  rep(i, n) {
    if (arr[i] * 4 * m >= sum)
      count++;
  }
  if (count >= m)
    exit(puts("Yes"));
  puts("No");
  go;
}
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> vec(N);
  int sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
    sum += vec.at(i);
  }
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (4 * M * vec.at(i) >= sum) {
      cnt++;
    }
  }
  if (cnt >= M)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> vec(N);
  int sum = 0;
  for (int i : vec) {
    cin >> vec.at(i);
    sum += vec.at(i);
  }
  int cnt = 0;
  for (int i : vec) {
    if (4 * M * vec.at(i) >= sum) {
      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 <vector>
using namespace std;

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

  vector<double> A(N);

  double sum = 0;

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

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

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

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 <algorithm>
#include <iostream>
#include <vector>
using namespace std;

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

  vector<int> A(N);

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

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

  if (A.at(M - 1) >= 1 / (4 * 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;
typedef long long ll;

// マクロ
// forループ関係
// 引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
// Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))   // 最大値を求める
#define MIN(x) *min_element(ALL(x))   // 最小値を求める
// 定数
#define INF 1000000000000 // 10^12:極めて大きい値,∞
#define MOD 1000000007    // 10^9+7:合同式の法
#define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用)
// 略記
#define PB push_back // vectorヘの挿入
#define MP make_pair // pairのコンストラクタ
#define F first      // pairの一つ目の要素
#define S second     // pairの二つ目の要素

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, A;
  ll ans = 0;
  double b, M = 0;
  cin >> N >> M;
  vector<ll> x(N);
  REP(i, N) {
    cin >> A;
    b += A;
    x[i] = A;
  }
  b *= (1 / (4 * M));
  REP(i, N) {
    if (x[i] >= b) {
      ans++;
    }
  }
  if (ans < M)
    cout << "No";
  else
    cout << "Yes";
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

// マクロ
// forループ関係
// 引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
// Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))   // 最大値を求める
#define MIN(x) *min_element(ALL(x))   // 最小値を求める
// 定数
#define INF 1000000000000 // 10^12:極めて大きい値,∞
#define MOD 1000000007    // 10^9+7:合同式の法
#define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用)
// 略記
#define PB push_back // vectorヘの挿入
#define MP make_pair // pairのコンストラクタ
#define F first      // pairの一つ目の要素
#define S second     // pairの二つ目の要素

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, A;
  ll ans = 0;
  double b, M = 0;
  ll x[N];
  cin >> N >> M;
  REP(i, N) {
    cin >> A;
    b += A;
    x[i] = A;
  }
  b = b * (1 / (4 * M));
  REP(i, N) {
    if (x[i] > b) {
      ans++;
    }
  }
  if (ans < M)
    cout << "No";
  else
    cout << "Yes";
}
Problem p02718 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i, m, n) for (lli i = m; i < n; i++)
#define rrep(i, m, n) for (lli i = m - 1; i >= n; i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(), N.end()), N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(), n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K, L, N, S) vector<L> K(N, S)
#define DV(K, L, N, M, S) vector<vector<L>> K(N, vector<L>(M, S))
#define TV(K, L, N, M, R, S)                                                   \\
  vector<vector<vector<L>>> K(N, vector<vector<L>>(M, vector<L>(R, S)))
#define pint pair<lli, lli>
#define paf(L, R) pair<L, R>
#define mod 1000000007
#define MAX 5100000
#define ALL(a) a.begin(), a.end()
#define chmax(a, b) a = (((a) < (b)) ? (b) : (a))
#define chmin(a, b) a = (((a) > (b)) ? (b) : (a))
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A, B, C, D, E, F, N, M, K, L, R, X, Y, Z, H, W, sum = 0, num = 0,
                                                      flag = 0;
  string S, T;
  cin >> N >> M;
  Vec(P, lli, N, 0);
  rep(i, 0, N) cin >> P[i];
  rep(i, 0, N) sum += P[i];
  if (sum % (4 * M))
    A = sum / (4 * M) + 1;
  else
    A = sum / (4 * M);
  rep(i, 0, N) if (P[i] >= A) num++;
  if (num >= M)
    Out("Yes");
  else
    Out("No");
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i, m, n) for (lli i = m; i < n; i++)
#define rrep(i, m, n) for (lli i = m - 1; i >= n; i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(), N.end()), N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(), n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K, L, N, S) vector<L> K(N, S)
#define DV(K, L, N, M, S) vector<vector<L>> K(N, vector<L>(M, S))
#define TV(K, L, N, M, R, S)                                                   \\
  vector<vector<vector<L>>> K(N, vector<vector<L>>(M, vector<L>(R, S)))
#define pint pair<lli, lli>
#define paf(L, R) pair<L, R>
#define mod 1000000007
#define MAX 5100000
#define ALL(a) a.begin(), a.end()
#define chmax(a, b) a = (((a) < (b)) ? (b) : (a))
#define chmin(a, b) a = (((a) > (b)) ? (b) : (a))
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A, B, C, D, E, F, N, M, K, L, R, X, Y, Z, H, W, sum = 0, num = 0,
                                                      flag = 0;
  string S, T;
  cin >> N >> M;
  Vec(P, lli, N, 0);
  rep(i, 0, N) cin >> P[i];
  rep(i, 0, N) sum += P[i];
  if (sum % (4 * M))
    A = sum / (4 * A) + 1;
  else
    A = sum / (4 * A);
  rep(i, 0, N) if (P[i] >= A) num++;
  if (num >= M)
    Out("Yes");
  else
    Out("No");
}
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(), greater<int>());
  if (4 * M * A.at(M - 1) < sum) {
    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;
  vector<int> A(N);
  long sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    sum += A.at(i);
  }
  sort(A.begin(), A.end(), greater<int>());
  if (4 * M * A.at(M) < sum) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  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);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }

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

  int A_sum = accumulate(A.begin(), A.end(), 0);
  double line = (A_sum + (4 * M) - 1) / (4 * M);
  for (int i = 0; i < M; i++) {
    if (A.at(i) < line) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << 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;

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

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

  int A_sum = accumulate(A.begin(), A.end(), 0);
  double line = A_sum / (4 * M);
  for (int i = 0; i < M; i++) {
    if (A.at(i) < line) {
      cout << "No" << endl;
      return 0;
    }
  }

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

#include <bits/stdc++.h>
#define ft(i, l, r) for (register int i = l; i <= r; i++)
#define fd(i, r, l) for (register int i = r; i >= l; i--)
using namespace std;
int n, m, a[2333], s, ans;
int main() {
  cin >> n >> m;
  ft(i, 1, n) {
    scanf("%d", &a[i]);
    s += a[i];
  }
  ft(i, 1, n) if (a[i] * 4 * m >= s) ans++;
  if (ans >= m)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}

Error: -11

Fixed submission:

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

int main() {
  int n, m, h = 0, s = 0, a[n];
  cin >> n >> m >> a[n];

  for (int i = a[1]; i < a[n]; i++) {
    h = h + a[i];
  }
  for (int i = a[1]; i < a[n]; i++) {
    if (a[i] > h / 4) {
      s++;
    } else {
      s + 0;
    }
  }
  if (s < m) {
    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, l, j, k = 0;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    k += a.at(i);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  j = 4 * m;
  l = k;
  k /= j;
  if (l % j > 0)
    k++;

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

  return 0;
}


Error: WA

Fixed submission:

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

int main() {
  int n, m, k = 0;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    k += a.at(i);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  m = 4 * m;
  int l = k;
  k /= m;
  if (l % m > 0)
    k++;

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

  return 0;
}