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

  if (vote.at(N - M) * 4 * M >= sum) {
    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() {
  double N, M, sum = 0;
  cin >> N >> M;
  vector<double> vote(N);
  for (int i = 1; i < N; i++) {
    cin >> vote.at(i);
    sum += vote.at(i);
  }
  sort(vote.begin(), vote.end());

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

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

int main() {

  ll n, m;
  ll count = 0;
  vector<ll> points;

  cin >> n >> m;

  rep(i, n) {
    ll point;

    cin >> point;

    points.push_back(point);
    count += point;
  }

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

  if (points.at(n - m) < (float)count / (4 * m)) {

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

  return 0;
}


Error: WA

Fixed submission:

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

int main() {

  int n, m;
  int count = 0;
  vector<int> points;
  int numMP = 1000;

  cin >> n >> m;

  rep(i, n) {
    int point;

    cin >> point;

    points.push_back(point);
    count += point;
  }

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

  if (points.at(m) < count / (4 * m)) {

    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;
  int V = 0;
  int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    V = V + A[i];
  }

  int tmp;

  for (int i = N; i > 0; i--) {
    for (int j = 1; j < i; j++) {
      if (A[j] > A[j - 1]) {
        tmp = A[j];
        A[j] = A[j - 1];
        A[j - 1] = tmp;
      }
    }
  }

  if (A[M - 1] * 4 * M >= V) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Error: -8

Fixed submission:

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

int main() {
  int N, M;
  cin >> N >> M;
  int A[N];

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

  for (int i = N; i > 0; i--) {
    for (int j = 1; j < i; j++) {
      if (A[j] > A[j - 1]) {
        int tmp = A[j];
        A[j] = A[j - 1];
        A[j - 1] = tmp;
      }
    }
  }

  int tol = 0;

  for (int i = 0; i < N; i++) {
    tol = tol + A[i];
  }

  int v = 0;

  for (int i = 0; i < M; i++) {
    if (A[i] < (tol / (1 / (4 * M)))) {
      v = v + 1;
    }
  }

  if (v == 0) {
    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;
  cin >> N >> M;
  vector<int> vo(N);
  for (int i = 0; i < N; i++) {
    cin >> vo.at(i);
    sum += vo.at(i);
  }
  sort(vo.begin(), vo.end(), greater<int>());
  cout << ((vo.at(M - 1) >= (sum + 4 * M - 1) / (4 * M)) ? "Yes" : "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, sum = 0;
  cin >> N >> M;
  vector<int> vo(N);
  for (int i = 0; i, N; i++) {
    cin >> vo.at(i);
    sum += vo.at(i);
  }
  sort(vo.begin(), vo.end(), greater<int>());
  cout << ((vo.at(M - 1) >= (sum + 4 * M - 1) / (4 * M)) ? "Yes" : "No")
       << endl;
}
Problem p02718 (C++) — buggy submission, verdict: Runtime Error


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

typedef long long ll;
#define pb push_back
#define F first
#define S second
#define ppp pair<ll, pair<ll, ll>>
#define pp pair<ll, ll>
#define all(x) (x).begin(), (x).end()
#define pi 3.14159265358
#define MOD 998244353

int main() {

  // #ifndef ONLINE_JUDGE
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  // freopen("error.txt", "w", stderr);
  // #endif

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

  ll n, m, i, j, k, l;

  cin >> n >> m;

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

  sort(a, a + n, greater<>());

  for (i = 0; i < m; i++) {
    if (a[i] * 4 * m < tot) {
      break;
    }
  }
  if (i == m) {
    cout << "Yes" << endl;
  } else
    cout << "No" << endl;
}


Error: -11

Fixed submission:


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

typedef long long ll;
#define pb push_back
#define F first
#define S second
#define ppp pair<ll, pair<ll, ll>>
#define pp pair<ll, ll>
#define all(x) (x).begin(), (x).end()
#define pi 3.14159265358
#define MOD 998244353

int main() {

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif

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

  ll n, m, i, j, k, l;

  cin >> n >> m;

  ll a[n];
  for (i = 0; i < n; i++)
    cin >> a[i];

  sort(a, a + n, greater<>());

  for (i = 0; i < m; i++) {
    if (a[i] * 4 * m < 1) {
      break;
    }
  }
  if (i == m) {
    cout << "YES" << endl;
  } else
    cout << "NO" << endl;
}
Problem p02718 (C++) — buggy submission, verdict: Runtime Error

#include <fstream>
#include <iostream>
#include <stdio.h>

using std::cin;
using std::cout;
using std::endl;
using std::terminate;

void solve() {
  int n, m;
  cin >> n >> m;
  int a[n];
  int all = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    all += a[i];
    a[i] *= 4 * m;
  }

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

  cout << (y >= m ? "Yes" : "No") << endl;
}

int main() {

#ifdef DEV
  std::ifstream in("AtCoder/ABC161/Popular Vote.input");
  cin.rdbuf(in.rdbuf());

  int t;
  cin >> t;
  for (int x = 1; x <= t; ++x) {
    solve();
  }
#else
  solve();
#endif

  return 0;
}


Error: -11

Fixed submission:

#include <fstream>
#include <iostream>
#include <stdio.h>

#define DEV 1

using std::cin;
using std::cout;
using std::endl;
using std::terminate;

void solve() {
  int n, m;
  cin >> n >> m;
  int a[n];
  int all = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    all += a[i];
    a[i] *= 4 * m;
  }

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

  cout << (y >= m ? "Yes" : "No") << endl;
}

int main() {

#ifdef DEV
  std::ifstream in("AtCoder/ABC161/Popular Vote.input");
  cin.rdbuf(in.rdbuf());

  int t;
  cin >> t;
  for (int x = 1; x <= t; ++x) {
    solve();
  }
#else
  solve();
#endif

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

#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define INF 1000000000
#define MOD 1000000007LL
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair

#define FOR(i, a, b) for (int i = (a); i <= (signed)(b); i++)
#define F0R(i, a) for (int i = 0; i < (signed)(a); i++)
#define RFOR(i, a, b) for (int i = (a); i >= b; i--)

#define MN 105
int n, m;
int a[MN];

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

  cin >> n >> m;
  int sm = 0;
  F0R(i, n) {
    cin >> a[i];
    sm += a[i];
  }
  int tot = (sm + 4 * m - 1) / (4 * m);
  int cnt = 0;
  F0R(i, n) {
    if (a[i] >= tot)
      ++cnt;
  }

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

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define INF 1000000000
#define MOD 1000000007LL
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair

#define FOR(i, a, b) for (int i = (a); i <= (signed)(b); i++)
#define F0R(i, a) for (int i = 0; i < (signed)(a); i++)
#define RFOR(i, a, b) for (int i = (a); i >= b; i--)

#define MN 21
int n, m;
int a[MN];

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

  cin >> n >> m;
  int sm = 0;
  F0R(i, n) {
    cin >> a[i];
    sm += a[i];
  }
  int tot = (sm + 4 * m - 1) / (4 * m);
  int cnt = 0;
  F0R(i, n) {
    if (a[i] >= tot)
      ++cnt;
  }

  if (cnt >= 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;

#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

void func() {

  ll n, m;
  cin >> n >> m;

  vector<ll> a;

  ll sum = 0;

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

    cin >> temp;
    sum = sum + temp;
    a.pb(temp);
  }

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

  ll j = n - 1;
  for (int i = 0; i < m; i++) {
    if (a[j] < ceil(1.0 * sum / (4 * m))) {
      cout << "No" << endl;
      return;
    }
    j--;
  }
  cout << "Yes" << endl;
}

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*/

  ll t = 1;
  // cin>>t;
  while (t--)
    func();
}

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;

#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

void func() {

  ll n, m;
  cin >> n >> m;

  vector<ll> a;

  ll sum = 0;

  for (int i = 0; i < n; i++) {
    ll temp;
    sum = sum + temp;
    cin >> temp;
    a.pb(temp);
  }

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

  ll j = n - 1;
  for (int i = 0; i < m; i++) {
    if (a[j] < (sum / (4 * m))) {
      cout << "No" << endl;
      return;
    }
    j--;
  }
  cout << "Yes" << endl;
}

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

  ll t = 1;
  // cin>>t;
  while (t--)
    func();
}
Problem p02718 (C++) — buggy submission, verdict: Runtime Error

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

int i;

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

  cin >> n >> m;
  vector<int> a(n);

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

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

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

  if (a[m - 1] >= (double)sum / (4.0 * m)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Error: -11

Fixed submission:

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

int i;

int main() {
  int n, m, sum = 0;
  vector<int> a;
  cin >> n >> m;

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

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

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

  if ((double)a[m - 1] >= (double)sum / (4 * m)) {
    cout << "Yes";
  } else {
    cout << "No";
  }
}
Problem p02718 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

#define ff first
#define ss second
#define pb push_back
#define sz size()

const int N = 1e5 + 5;
const int MOD = 1e9 + 7;

int main() {

  int n, m;

  cin >> n >> m;
  std::vector<int> v(n);
  int tot = 0;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    tot += v[i];
  }
  sort(v.begin(), v.end(), greater<int>());

  bool flag = 0;
  for (int i = 0; i < m; i++) {
    if (v[i] * 4 * m < tot) {
      flag = 1;
      break;
    }
  }

  if (flag)
    cout << "No\\n";
  else
    cout << "Yes\\n";

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

#define ff first
#define ss second
#define pb push_back
#define sz size()

const int N = 1e5 + 5;
const int MOD = 1e9 + 7;

int main() {

  int n, m;
  std::vector<int> v(n);

  cin >> n >> m;
  int tot = 0;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    tot += v[i];
  }
  sort(v.begin(), v.end(), greater<int>());

  bool flag = 0;
  for (int i = 0; i < m; i++) {
    if (v[i] * 4 * m < tot) {
      flag = 1;
      break;
    }
  }

  if (flag)
    cout << "NO\\n";
  else
    cout << "Yes\\n";

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

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int a[n], s = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    s += a[i];
  }
  int v = s / (4 * k), yy = 4 * k;
  sort(a, a + n);
  for (int i = n - 1; i >= 0; i--) {
    if (s % (yy) == 0 && a[i] >= v)
      k--;
    else if (a[i] > v)
      k--;
  }
  if (k > 0)
    cout << "No";
  else
    cout << "Yes";
  return 0;
}

Error: -8

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int a[n], s = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    s += a[i];
  }
  int v = s / (4 * k);
  sort(a, a + n);
  for (int i = n - 1; i >= 0; i--) {
    if (s % (k * 4) == 0 && a[i] >= v)
      k--;
    else if (a[i] > v)
      k--;
  }
  if (k > 0)
    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> tokuhyou(N);
  int soutokuhyou = 0;
  for (int i = 0; i < N; i++) {
    cin >> tokuhyou.at(i);
    soutokuhyou += tokuhyou.at(i);
  }
  int count = 0;
  for (int i = 0; i < N; i++) {
    if (tokuhyou.at(i) * 4 * M < soutokuhyou) {
      count += 0;
    } else {
      count += 1;
    }
  }
  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;

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

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define MOD 1000000007
#define len(x) x.size()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(v) v.begin(), v.end()
#define alla(a, n) a, a + n
#define F(i, n) for (i = 0; i < n; i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<string> vs;

int32_t main() {

  // #ifndef ONLINE_JUDGE
  // freopen("input.txt", "r", stdin) ;
  // freopen("output.txt", "w", stdout) ;
  // #endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int n, m, i, sum = 0, count = 0, a[10000];
  cin >> n >> m;
  F(i, n) {
    cin >> a[i];
    sum += a[i];
  }
  // sort(a,a+n,greater<int>());
  int store = ceil((sum / (4.0 * (double)m)));
  for (i = 0; i < n; i++) {
    if (a[i] >= store)
      count++;
  }
  // cout<<count<<" "<<sum<<" "<<store<<endl;
  if (count >= m)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Error: -8

Fixed submission:

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define MOD 1000000007
#define len(x) x.size()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(v) v.begin(), v.end()
#define alla(a, n) a, a + n
#define F(i, n) for (i = 0; i < n; i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<string> vs;

int32_t main() {

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int n, m, i, sum = 0, count = 0, a[10000];
  cin >> n >> m;
  F(i, n) {
    cin >> a[i];
    sum += a[i];
  }
  sort(a, a + n, greater<int>());
  int store = ceil((sum / (4 * m)));
  for (i = 0; i < n; i++) {
    if (a[i] >= store)
      count++;
  }
  cout << count << " " << sum << " " << store << endl;
  if (count >= m)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p02718 (C++) — buggy submission, verdict: Time Limit Exceeded

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, n, m, sum = 0;
  cin >> n >> m;
  vector<int> vec(n);
  for (i = 0; i < n; i++)
    cin >> vec.at(i);
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  for (i = 0; i < n; i++)
    sum += vec.at(i);
  while (i = m) {
    for (i = 0; i < m; i++) {
      if (vec.at(i) < (sum / 4 * m))
        continue;
      else
        cout << "No" << endl;
      break;
    }
    cout << "Yes" << endl;
  }
}
Problem p02718 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> v;

int main() {
  ll m, n, tmp;

  // freopen("in.txt","r",stdin);
  // freopen("out.txt","w",stdout);
  cin >> n >> m;

  int sum = 0;

  for (int i = 0; i < n; i++) {
    cin >> tmp;
    v.push_back(tmp);
    sum += tmp;
  }
  sort(v.begin(), v.end());
  if (sum % (4 * m) == 0)
    sum = sum / (4 * m);
  else
    sum = (sum + 4 * m) / (4 * m);
  // cout<<sum<<endl;
  bool flag = false;
  for (int i = v.size() - m; i < v.size(); i++) {

    if (v[i] < sum)
      flag = true;
  }
  if (flag) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> v;

int main() {
  ll m, n, tmp;

  // freopen("in.txt","r",stdin);
  // freopen("out.txt","w",stdout);
  cin >> n >> m;

  int sum = 0;

  for (int i = 0; i < n; i++) {
    cin >> tmp;
    v.push_back(tmp);
    sum += tmp;
  }
  sort(v.begin(), v.end());
  if (sum % (4 * m) == 0)
    sum = sum / (4 * m);
  else
    sum = (sum + 4) / (4 * m);
  // cout<<sum<<endl;
  bool flag = false;
  for (int i = v.size() - 1; v.size() - m >= 0 && i >= v.size() - m; i--) {

    if (v[i] < sum)
      flag = true;
  }
  if (flag) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}
Problem p02718 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long int
#define endl "\\n"
#define mod 1000000007
#define mem(a, val) memset(a, val, sizeof(a))
#define ps(x, noOfDecimal) fixed << setprecision(noOfDecimal) << x

using namespace std;
int main() {
  // #ifndef ONLINE_JUDGE
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  // #endif
  std::ios::sync_with_stdio(false);

  int n, m;
  cin >> n >> m;
  vector<int> arr(n);
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
  }

  double d = 1;
  d /= m;
  d /= 4;
  // cout<<d<<endl;
  int ct = 0;
  for (int i = 0; i < n; ++i) {
    double chk = arr[i];
    chk /= sum;
    // cout<<chk<<endl;
    if (d <= chk)
      ct++;
  }
  if (ct >= m)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define endl "\\n"
#define mod 1000000007
#define mem(a, val) memset(a, val, sizeof(a))
#define ps(x, noOfDecimal) fixed << setprecision(noOfDecimal) << x

using namespace std;
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  std::ios::sync_with_stdio(false);

  int n, m;
  cin >> n >> m;
  vector<int> arr(n);
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
  }

  double d = 1;
  d /= m;
  d /= 4;
  // cout<<d<<endl;
  int ct = 0;
  for (int i = 0; i < n; ++i) {
    double chk = arr[i];
    chk /= sum;
    // cout<<chk<<endl;
    if (d <= chk)
      ct++;
  }
  if (ct >= m)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}
Problem p02718 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  rep(i, n) { cin >> a[i]; }
  int sum_point = 0;
  rep(i, n) { sum_point += a[i]; }
  int checked = 0;
  bool ans = false;
  rep(i, n) {
    if (a[i] * 4 * m >= sum_point) {
      checked++;
    }
    if (checked == m) {
      ans = true;
      break;
    }
  }

  if (ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  rep(i, n) { cin >> a[i]; }
  int sum_point = 0;
  rep(i, n) { sum_point += a[i]; }
  int checked = 0;
  bool ans = false;
  rep(i, n) {
    if (a[i] >= sum_point / (4 * m)) {
      checked++;
    }
    if (checked == m) {
      ans = true;
      break;
    }
  }

  if (ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  while (true)
    ;
}
Problem p02718 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int main(void) {
  int N, M;
  double MAX = 0;
  if (scanf("%d %d", &N, &M) == 1) {
    M++;
    M--;
  }
  int A[N][2], i, CHECK = 0;
  for (i = 0; i < N; i++) {
    if (scanf("%d", &A[i][0]) == 1)
      M++;
    M--;
    A[i][1] = 0;
    MAX = MAX + A[i][0];
  }
  MAX = MAX / (4 * M);
  for (i = 0; i < N; i++) {
    if (MAX <= A[i][0])
      CHECK++;
  }
  if (CHECK >= M)
    printf("Yes");
  else
    printf("No");
}


Error: -11

Fixed submission:

#include <stdio.h>
int main(void) {
  int N, M, MAX = 0;
  scanf("%d %d", N, M);
  int A[N][2], i, CHECK = 0;
  for (i = 0; i < N; i++) {
    scanf("%d", A[i][0]);
    A[i][1] = 0;
    MAX = MAX + A[i][0];
  }
  MAX = MAX / (4 * M);
  for (i = 0; i < N; i++) {
    if (MAX <= A[i][0])
      CHECK++;
  }
  if (CHECK >= M)
    printf("Yes");
  else
    printf("No");
}