prithivMLmods/Coder-Stat huggingface dataset:
Problem p02911 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {

  int N;
  int K;
  int Q;
  cin >> N >> K >> Q;

  int num = Q - K + 1;
  int num2;

  vector<int> A(Q);

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

  vector<int> B(N);

  if (Q - K < 0) {
    for (int i = 0; i < N; ++i) {
      cout << "Yes" << endl;
    }
  } else {
    for (int j = 0; j < Q; ++j) {
      num2 = A[j] - 1;

      B[num2] = B[num2] + 1;
    }
    for (int i = 0; i < N; ++i) {
      if (B[i] >= num) {
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
    }
  }
}


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

  int N;
  int K;
  int Q;
  cin >> N >> K >> Q;

  int num = Q - K + 1;
  int num2;

  vector<int> A(Q);

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

  vector<int> B(N);

  if (Q - K < 0) {
    for (int i = 0; i < N; ++i) {
      cout << "Yes" << endl;
    }
  } else {
    for (int j = 0; j < Q; ++j) {
      num2 = A[j] - 1;

      B[num2] = B[num2] + 1;
    }
    for (int i = 0; i < N; ++i) {
      if (B[i] >= num) {
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
    }
  }
}
Problem p02911 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  ll n, k, q;
  cin >> n >> k >> q;
  vector<ll> vec(n, k - q);
  ll tmp;
  for (int i = 0; i < q; i++) {
    cin >> tmp;
    vec.at(tmp)++;
  }
  for (int i = 0; i < n; i++) {
    if (vec.at(i) > 0) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  ll n, k, q;
  cin >> n >> k >> q;
  vector<ll> vec(n, k - q);
  ll tmp;
  for (int i = 0; i < q; i++) {
    cin >> tmp;
    vec.at(tmp - 1)++;
  }
  for (int i = 0; i < n; i++) {
    if (vec.at(i) > 0) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}
Problem p02911 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>

using namespace std;

int main() {
  long long n, k, q, line;
  long long *a, *b;
  cin >> n;
  cin >> k;
  cin >> q;
  line = q - k + 1;
  a = new long long[q];
  b = new long long[n];
  for (int i = 0; i < n; i++) {
    b[i] = 0;
  }
  for (int i = 0; i < q; i++) {
    cin >> a[i];
    b[a[i] - 1]++;
  }
  for (int i = 0; i < q; i++) {
    if (b[i] >= line) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}

Fixed submission:
#include <iostream>
#include <string>

using namespace std;

int main() {
  long long n, k, q, line;
  long long *a, *b;
  cin >> n;
  cin >> k;
  cin >> q;
  line = q - k + 1;
  a = new long long[q];
  b = new long long[n];
  for (int i = 0; i < n; i++) {
    b[i] = 0;
  }
  for (int i = 0; i < q; i++) {
    cin >> a[i];
    b[a[i] - 1]++;
  }
  for (int i = 0; i < n; i++) {
    if (b[i] >= line) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}
Problem p02911 (C++)

Buggy submission (status: Time Limit Exceeded):
#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() {
  ll n, k, q;
  cin >> n >> k >> q;
  vector<ll> a(q);
  rep(i, q) cin >> a[i];
  vector<ll> pa(n);
  rep(i, n) pa[i] = k;
  rep(i, q) {
    rep(j, n) {
      if ((a[i] - 1) != j)
        pa[j]--;
    }
    // rep(i,n) cout<<pa[i]<<" ";
    // cout<<endl;
  }
  rep(i, n) {
    if (pa[i] > 0)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
  return 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;
using P = pair<int, int>;

int main() {
  ll n, k, q;
  cin >> n >> k >> q;
  vector<ll> a(q);
  rep(i, q) cin >> a[i];
  vector<ll> pa(n);
  rep(i, n) pa[i] = k - q;
  rep(i, q) { pa[a[i] - 1]++; }
  rep(i, n) {
    if (pa[i] > 0)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
  return 0;
}
Problem p02911 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, K, Q;
  cin >> N >> K >> Q;
  vector<int> A(N);
  for (int i = 0; i < Q; i++) {
    cin >> A.at(i);
  }
  vector<int> ans(N);
  for (int i = 0; i < N; i++) {
    ans.at(i) = K - Q;
  }
  for (int i = 0; i < Q; i++) {
    ans.at(A.at(i) - 1)++;
  }
  for (int i = 0; i < N; i++) {
    if (ans.at(i) > 0) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}


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

int main() {
  int N, K, Q;
  cin >> N >> K >> Q;
  vector<int> A(Q);
  for (int i = 0; i < Q; i++) {
    cin >> A.at(i);
  }
  vector<int> ans(N);
  for (int i = 0; i < N; i++) {
    ans.at(i) = K - Q;
  }
  for (int i = 0; i < Q; i++) {
    ans.at(A.at(i) - 1)++;
  }
  for (int i = 0; i < N; i++) {
    if (ans.at(i) > 0) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}
Problem p02911 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, K, Q;
  cin >> N >> K >> Q;
  vector<int> A(N);
  vector<int> B(N);
  vector<string> C(N);

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

    B.at(i) = B.at(i) + K - Q;
    C.at(i) = "Yes";
  }
  for (int i = 0; i < Q; i++) {
    cin >> A.at(i);
    B.at(A.at(i) - 1)++;
  }
  for (int i = 0; i < N; i++) {
    if (B.at(i) <= 0) {
      C.at(i) = "No";
    }
    cout << C.at(i) << endl;
  }
}

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

int main() {
  int N, K, Q;
  cin >> N >> K >> Q;
  vector<int> A(Q);
  vector<int> B(N);
  vector<string> C(N);

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

    B.at(i) = B.at(i) + K - Q;
    C.at(i) = "Yes";
  }
  for (int i = 0; i < Q; i++) {
    cin >> A.at(i);
    B.at(A.at(i) - 1)++;
  }
  for (int i = 0; i < N; i++) {
    if (B.at(i) <= 0) {
      C.at(i) = "No";
    }
    cout << C.at(i) << endl;
  }
}
Problem p02911 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  unsigned int n, q;
  unsigned long long int k;
  cin >> n >> k >> q;
  // cout << n << ',' << k << ',' << q << endl;

  vector<unsigned int> a(q);
  for (unsigned int i = 0; i < q; ++i) {
    cin >> a.at(i);
  }

  // cout << n << ',' << k << ',' << q << endl;
  vector<int> score(n, k - q);

  for (unsigned int i = 0; i < q; ++i) {
    score.at(a.at(i))++;
  }

  for (unsigned int i = 0; i < n; ++i) {
    // cout << "i: " << i << ", score[" << i << "]: " << score.at(i) << endl;
    if (score.at(i) <= 0) {
      cout << "No" << endl;
    } else {
      cout << "Yes" << endl;
    }
  }
}


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

int main() {
  unsigned int n, q;
  unsigned long long int k;
  cin >> n >> k >> q;
  // cout << n << ',' << k << ',' << q << endl;

  vector<unsigned int> a(q);
  for (unsigned int i = 0; i < q; ++i) {
    cin >> a.at(i);
  }

  // cout << n << ',' << k << ',' << q << endl;
  vector<int> score(n, k - q);

  for (unsigned int i = 0; i < q; ++i) {
    score.at(a.at(i) - 1)++;
  }

  for (unsigned int i = 0; i < n; ++i) {
    // cout << "i: " << i << ", score[" << i << "]: " << score.at(i) << endl;
    if (score.at(i) <= 0) {
      cout << "No" << endl;
    } else {
      cout << "Yes" << endl;
    }
  }
}
Problem p02911 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;

int main() {
  int n, k, q;
  cin >> n >> k >> q;
  vector<int> a(q);
  rep(i, q) cin >> a[i];
  vector<int> ans(n);
  rep(i, n) ans[i] = k - q;
  rep(i, n) { ans[a[i] - 1]++; }
  rep(i, n) {
    if (ans[i] > 0)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;

int main() {
  int n, k, q;
  cin >> n >> k >> q;
  vector<int> a(q);
  rep(i, q) cin >> a[i];
  vector<int> ans(n);
  rep(i, n) ans[i] = k - q;
  rep(i, q) { ans[a[i] - 1]++; }
  rep(i, n) {
    if (ans[i] > 0)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
  return 0;
}
Problem p02911 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define vl vector<ll>

int main() {
  ll n, k, q;
  cin >> n >> k >> q;
  vl a(n);
  rep(i, n) cin >> a.at(i);

  vl p(n);
  vector<string> ans(n);
  rep(i, q) p.at(a.at(i) - 1)++;

  rep(i, n) {
    if (k - q + p.at(i) > 0) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}

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

int main() {
  ll n, k, q;
  cin >> n >> k >> q;
  vl a(q);
  rep(i, q) cin >> a.at(i);

  vl p(n);
  vector<string> ans(n);
  rep(i, q) p.at(a.at(i) - 1)++;

  rep(i, n) {
    if (k - q + p.at(i) > 0) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}
Problem p02911 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
  int N, K, Q, p[10000] = {};
  cin >> N >> K >> Q;
  REP(i, Q) {
    int A;
    cin >> A;
    p[A - 1]++;
  }
  REP(i, N) {
    if (K - Q + p[i] > 0)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
  int N, K, Q, p[100000] = {};
  cin >> N >> K >> Q;
  REP(i, Q) {
    int A;
    cin >> A;
    p[A - 1]++;
  }
  REP(i, N) {
    if (K - Q + p[i] > 0)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
  return 0;
}
Problem p02912 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long N, M, T;
  T = 0;
  cin >> N >> M;
  vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  for (long long i = 0; i < M; i++) {
    if (N > 10) {
      if (A[N - 2] * 2 <= A[N - 1] && i < M && A[N - 1] > 0) {
        while (A[N - 2] * 2 > A[N - 1] && i < M && A[N - 1] > 0) {
          A[N - 1] /= 2;
          i++;
        }
        // cout << "a";
      }
      while (A[0] * 2 >= A[N - 1] && i + N < M && A[N - 1] > 0) {
        for (int i2 = N - 1; i2 >= 0; i2--) {
          A[i2] /= 2;
          i++;
          // cout << "b";
          // cout << i;
        }
      }
      if (A[0] * 2 >= A[N - 1] && i + N >= M && A[N - 1] > 0) {
        long long i3 = N - 1 - (M - i) + 1;
        for (int i2 = N - 1; i2 >= i3; i2--) {
          A[i2] /= 2;
          i++;
          // cout << "c";
        }
      } else if (A[N - 1] > 0) {
        long long B = A[N - 1] / 2;
        int i3 = N - 1;
        while (A[i3] >= B && i < M && A[N - 1] > 0) {
          A[i3] /= 2;
          i3--;
          i++;
          // cout << "d";
        }
      }

    } else {
      A[N - 1] /= 2;
      i++;
    }
    sort(A.begin(), A.end());
    if (A[N - 1] == 0) {
      i = M;
    }
    // cout << "WWO";
    i--;
  }
  for (int i = 0; i < N; i++) {
    T += A[i];
  }
  cout << T << endl;
}


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

int main() {
  long long N, M, T;
  T = 0;
  cin >> N >> M;
  vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  for (long long i = 0; i < M; i++) {
    if (N > 10) {
      if (A[N - 2] * 2 <= A[N - 1] && i < M && A[N - 1] > 0) {
        while (A[N - 2] * 2 > A[N - 1] && i < M && A[N - 1] > 0) {
          A[N - 1] /= 2;
          i++;
        }
        // cout << "a";
      }
      while (A[0] * 2 >= A[N - 1] && i + N < M && A[N - 1] > 0) {
        for (int i2 = N - 1; i2 >= 0; i2--) {
          A[i2] /= 2;
          i++;
          // cout << "b";
          // cout << i;
        }
      }
      if (A[0] * 2 >= A[N - 1] && i + N >= M && A[N - 1] > 0) {
        long long i3 = N - 1 - (M - i) + 1;
        for (int i2 = N - 1; i2 >= i3; i2--) {
          A[i2] /= 2;
          i++;
          // cout << "c";
        }
      } else if (A[N - 1] > 0) {
        long long B = A[N - 1] / 2;
        int i3 = N - 1;
        while (A[i3] >= B && i < M && A[N - 1] > 0 && i3 >= 0) {
          A[i3] /= 2;
          i3--;
          i++;
          // cout << "d";
        }
      }

    } else {
      A[N - 1] /= 2;
      i++;
    }
    sort(A.begin(), A.end());
    if (A[N - 1] == 0) {
      i = M;
    }
    // cout << "WWO";
    i--;
  }
  for (int i = 0; i < N; i++) {
    T += A[i];
  }
  cout << T << endl;
}
Problem p02912 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  vector<int>::iterator itr;
  size_t index;
  while (m-- != 0) {
    itr = max_element(a.begin(), a.end());
    index = distance(a.begin(), itr);
    a[index] /= 2;
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    ans += a[i];
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  for (int i = 0; m; i++) {
    if (i == n)
      i = 0;
    if (a[0] > a[i]) {
      sort(a.begin(), a.end());
      reverse(a.begin(), a.end());
      i = -1;
      continue;
    }
    a[i] /= 2;
    m--;
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    ans += a[i];
  }
  cout << ans << endl;
  return 0;
}
Problem p02912 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define int long long

int N, M;
vector<int> V(10);
int ans;

signed main() {
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    ans += a;
    int tmp = 1;
    for (int j = 0; j < 50; j++) {
      V.push_back(a / tmp - a / (tmp * 2));
      tmp *= 2;
    }
  }

  sort(V.rbegin(), V.rend());
  for (int i = 0; i < M; i++)
    ans -= V[i];

  cout << ans << endl;

  return 0;
}

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

#define int long long

int N, M;
vector<int> V(10);
int ans;

signed main() {
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    ans += a;
    int tmp = 1;
    for (int j = 0; j < 50; j++) {
      V.push_back(a / tmp - a / (tmp * 2));
      tmp *= 2;
    }
  }

  sort(V.rbegin(), V.rend());
  for (int i = 0; i < min(M, (int)V.size()); i++)
    ans -= V[i];

  cout << ans << endl;

  return 0;
}
Problem p02912 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  priority_queue<int> que;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    que.push(a);
  }

  while (M > 0) {
    int t = que.top();
    que.pop();
    M--;
    t /= 2;
    if (t > 0)
      que.push(t);
  }

  long long res = 0;
  while (!que.empty()) {
    int t = que.top();
    que.pop();
    res += t;
  }

  cout << res << endl;
  return 0;
}

Fixed submission:
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  priority_queue<int> que;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    que.push(a);
  }

  while (M > 0 && !que.empty()) {
    int t = que.top();
    que.pop();
    M--;
    t /= 2;
    if (t > 0)
      que.push(t);
  }

  long long res = 0;
  while (!que.empty()) {
    int t = que.top();
    que.pop();
    res += t;
  }

  cout << res << endl;
  return 0;
}
Problem p02912 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  priority_queue<int> p;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    p.push(tmp);
  }
  for (int i = 0; i < m; i++) {
    int tmp = p.top();
    p.pop();
    p.push(tmp / 2);
  }
  long long int ans = 0;
  while (!p.empty()) {
    ans += p.top();
    p.pop();
  }
  cout << ans;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  priority_queue<int> p;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    p.push(tmp);
  }
  for (int i = 0; i < m; i++) {
    int tmp = p.top();
    p.pop();
    p.push(tmp / 2);
  }
  long long int ans = 0;
  while (!p.empty()) {
    ans += p.top();
    p.pop();
  }
  cout << ans;
  return 0;
}
Problem p02912 (Python)

Buggy submission (status: Runtime Error):
import heapq

n, m = map(int, input().split())
a = map(int, input().split())
a = map(lambda x: -x, a)
heapq.heapify(a)

for i in range(m):
    tmp = -heapq.heappop(a) // 2
    heapq.heappush(a, -tmp)

print(-sum(a))


Fixed submission:
import heapq

n, m = map(int, input().split())
a = map(int, input().split())
a = list(map(lambda x: -x, a))
heapq.heapify(a)

for i in range(m):
    tmp = -heapq.heappop(a) // 2
    heapq.heappush(a, -tmp)

print(-sum(a))
Problem p02912 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, pair<int, int>> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

  int n, m, a[112345];
  int b[11234][31];
  memset(b, 0, sizeof(b));

  ll sum = 0;

  cin >> n >> m;
  REP(i, n) {
    cin >> a[i];
    sum += a[i];

    ll j = 0;
    while (true) {
      b[i][j] = a[i] / (1LL << j);

      if (a[i] / (1LL << j) == 0)
        break;

      j++;
    }
  }

  priority_queue<P> q;

  REP(i, n) { q.push({b[i][0] - b[i][1], {i, 1}}); }

  while (m) {
    P p = q.top();
    q.pop();

    sum -= p.first;
    m--;
    q.push({b[p.second.first][p.second.second] -
                b[p.second.first][p.second.second + 1],
            {p.second.first, p.second.second + 1}});
  }

  cout << sum << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, pair<int, int>> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

  int n, m, a[112345];
  int b[112345][31];
  memset(b, 0, sizeof(b));

  ll sum = 0;

  cin >> n >> m;
  REP(i, n) {
    cin >> a[i];
    sum += a[i];

    ll j = 0;
    while (true) {
      b[i][j] = a[i] / (1LL << j);

      if (a[i] / (1LL << j) == 0)
        break;

      j++;
    }
  }

  priority_queue<P> q;

  REP(i, n) { q.push({b[i][0] - b[i][1], {i, 1}}); }

  while (m) {
    P p = q.top();
    q.pop();

    sum -= p.first;
    m--;
    q.push({b[p.second.first][p.second.second] -
                b[p.second.first][p.second.second + 1],
            {p.second.first, p.second.second + 1}});
  }

  cout << sum << endl;

  return 0;
}
Problem p02912 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <numeric>
#include <queue>
#include <stdio.h>
#include <vector>
using namespace std;
int main() {
  long N, M;
  scanf("%ld", &N);
  scanf("%ld", &M);
  std::priority_queue<long> que;
  for (long i = 0; i < N; i++) {
    long tmp;
    scanf("%ld", tmp);
    que.push(tmp);
  }

  long tmp;
  for (long i = 0; i < M; i++) {
    tmp = que.top();
    que.pop();
    que.push(tmp / 2);
  }

  long long ans = 0;

  for (long i = 0; i < N; i++) {
    ans += que.top();
    que.pop();
  }

  printf("%ld\n", ans);

  return 0;
}

Fixed submission:
#include <algorithm>
#include <numeric>
#include <queue>
#include <stdio.h>
#include <vector>
using namespace std;
int main() {
  long N, M;
  scanf("%ld", &N);
  scanf("%ld", &M);
  std::priority_queue<long> que;
  for (long i = 0; i < N; i++) {
    long tmp;
    scanf("%ld", &tmp);
    que.push(tmp);
  }

  long tmp;
  for (long i = 0; i < M; i++) {
    tmp = que.top();
    que.pop();
    que.push(tmp / 2);
  }

  long long ans = 0;

  for (long i = 0; i < N; i++) {
    ans += que.top();
    que.pop();
  }

  printf("%ld\n", ans);

  return 0;
}
Problem p02912 (C++)

Buggy submission (status: Runtime Error):
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
// #include<C:\Users\J\Desktop\AC\athead.h>
#define showa(v)                                                               \
  for (int iii = 0; iii < v.size(); iii++) {                                   \
    cout << v[iii] << " ";                                                     \
  }                                                                            \
  cout << endl;
#define show(iiii) cout << iiii << endl;
#define shows(iiiii) cout << iiiii << " ";
#define divs 1000000007
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stdio.h>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  multiset<int> a;
  unsigned long long int sum = 0;
  rep(i, n) {
    int buf;
    cin >> buf;
    a.insert(buf);
    sum += buf;
  }
  unsigned long long int sakugen = 0;
  rep(i, m) {
    auto itr = a.end();
    int targ = *itr;
    sakugen += (targ - targ / 2);
    a.erase(itr);
    a.insert(targ / 2);
  }
  cout << sum - sakugen;
}


Fixed submission:
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
// #include<C:\Users\J\Desktop\AC\athead.h>
#define showa(v)                                                               \
  for (int iii = 0; iii < v.size(); iii++) {                                   \
    cout << v[iii] << " ";                                                     \
  }                                                                            \
  cout << endl;
#define show(iiii) cout << iiii << endl;
#define shows(iiiii) cout << iiiii << " ";
#define divs 1000000007
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stdio.h>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  multiset<int> a;
  unsigned long long int sum = 0;
  rep(i, n) {
    int buf;
    cin >> buf;
    a.insert(buf);
    sum += buf;
  }
  unsigned long long int sakugen = 0;
  rep(i, m) {
    auto itr = a.end();
    itr--;
    int targ = *itr;
    sakugen += (targ - targ / 2);
    a.erase(itr);
    a.insert(targ / 2);
  }
  cout << sum - sakugen;
}
Problem p02912 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
// Compiler version g++ 6.3.0

int main() {
  ll n, m, ans = 0;
  cin >> n >> m;
  vector<ll> x;
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    ans += a;
    while (a != 1) {
      x.push_back(a - a / 2);
      a = a / 2;
    }
    x.push_back(1);
  }
  sort(x.begin(), x.end());
  ll y = x.size();
  for (int i = 0; i < m; i++) {
    ans -= x.at(y - i - 1);
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
// Compiler version g++ 6.3.0

int main() {
  ll n, m, ans = 0;
  cin >> n >> m;
  vector<ll> x;
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    ans += a;
    while (a != 1) {
      x.push_back(a - a / 2);
      a = a / 2;
    }
    x.push_back(1);
  }
  sort(x.begin(), x.end());
  ll y = x.size();
  if (x.size() <= m) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < m; i++) {
    ans -= x.at(y - i - 1);
  }
  cout << ans << endl;
}
Problem p02912 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <queue>

int main() {
  int n, m;
  std::cin >> n >> m;
  std::priority_queue<long long> que;

  int i;
  for (i = 0; i < n; i++) {
    long A;
    std::cin >> A;
  }
  for (i = 0; i < m; i++) {
    long long t = que.top();
    que.pop();
    que.push(t / 2);
  }

  long long res = 0;
  while (!que.empty()) {
    res += que.top();
    que.pop();
  }
  std::cout << res;
}

Fixed submission:
#include <iostream>
#include <queue>

int main() {
  int n, m;
  std::cin >> n >> m;
  std::priority_queue<long long> que;

  int i;
  for (i = 0; i < n; i++) {
    long A;
    std::cin >> A;
    que.push(A);
  }
  for (i = 0; i < m; i++) {
    long long t = que.top();
    que.pop();
    que.push(t / 2);
  }

  long long res = 0;
  while (!que.empty()) {
    res += que.top();
    que.pop();
  }
  std::cout << res;
}
Problem p02912 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
long long ans;
inline int nextInt() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  multiset<int> A;
  while (N--) {
    A.insert(nextInt());
  }
  while (M--) {
    int a = *prev(A.end());
    A.erase(prev(A.end()));
    a /= 2;
    A.insert(a);
  }
  for (auto &a : A) {
    ans += a;
  }
  printf("%lld\n", ans);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
long long ans;
inline int nextInt() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  multiset<int> A;
  while (N--) {
    int a;
    cin >> a;
    A.insert(a);
  }
  while (M--) {
    int a = *prev(A.end());
    A.erase(prev(A.end()));
    a /= 2;
    A.insert(a);
  }
  for (auto &a : A) {
    ans += a;
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p02912 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;

ll mod = 1e9 + 7ll;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const ll inf = 1ll << 60;

int n, m;
vector<pair<int, int>> seg(210000);
int l = 0;

void kousin(int i, int k) {
  // i番目の値をkに更新
  int pointer = (1 << l) - 1 + i;
  seg.at(pointer) = make_pair(k, i);
  rp(salkj, 0, l) {
    pointer = (pointer + 1) / 2 - 1;
    seg.at(pointer) = max(seg.at(pointer * 2 + 1), seg.at(pointer * 2 + 2));
  }
}

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

  // セグ木の大きさを決める
  while (1 << l < n)
    l++;

  // 入力を受けてセグ木を構成
  rp(i, 0, n) {
    int a;
    scanf("%d", &a);
    kousin(i, a);
  }

  // m回、クエリを実行
  // 今回の場合クエリは、全範囲の中で最大のものの値を半分にする

  rp(i, 0, m) { kousin(seg.at(0).second, seg.at(0).first / 2); }

  ll ans = 0;

  rp(i, 0, n) { ans += seg.at((1 << l) - 1 + i).first; }
  printf("%lld", ans);
  return 0;
}


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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;

ll mod = 1e9 + 7ll;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const ll inf = 1ll << 60;

int n, m;
vector<pair<int, int>> seg(300000);
int l = 0;

void kousin(int i, int k) {
  // i番目の値をkに更新
  int pointer = (1 << l) - 1 + i;
  seg.at(pointer) = make_pair(k, i);
  rp(salkj, 0, l) {
    pointer = (pointer + 1) / 2 - 1;
    seg.at(pointer) = max(seg.at(pointer * 2 + 1), seg.at(pointer * 2 + 2));
  }
}

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

  // セグ木の大きさを決める
  while (1 << l < n)
    l++;

  // 入力を受けてセグ木を構成
  rp(i, 0, n) {
    int a;
    scanf("%d", &a);
    kousin(i, a);
  }

  // m回、クエリを実行
  // 今回の場合クエリは、全範囲の中で最大のものの値を半分にする

  rp(i, 0, m) { kousin(seg.at(0).second, seg.at(0).first / 2); }

  ll ans = 0;

  rp(i, 0, n) { ans += seg.at((1 << l) - 1 + i).first; }
  printf("%lld", ans);
  return 0;
}
Problem p02912 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define int long long

signed main() {

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

  int n, m;
  cin >> n >> m;
  priority_queue<int> q;
  rep(i, n) {
    int a;
    cin >> a;
    q.push(a);
  }
  rep(i, m) {
    int a = q.top();
    q.pop();
    q.push(a / 2);
  }
  int ans = 0;
  rep(i, n) {
    ans += q.top();
    q.pop();
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define int long long

signed main() {

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

  int n, m;
  cin >> n >> m;
  priority_queue<int> q;
  rep(i, n) {
    int a;
    cin >> a;
    q.push(a);
  }
  rep(i, m) {
    int a = q.top();
    q.pop();
    q.push(a / 2);
  }
  int ans = 0;
  rep(i, n) {
    ans += q.top();
    q.pop();
  }
  cout << ans << endl;
  return 0;
}
Problem p02912 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, j) for (long long i = 0; i < j; i++)
#define int long long

using namespace std;

signed main() {
  int N, M, x;
  cin >> N >> M;
  vector<int> A_arr;
  vector<int> A_subarr;
  rep(i, N) {
    cin >> x;
    A_arr.push_back(x);
  }
  sort(A_arr.begin(), A_arr.end(), std::greater<int>());
  while (M > 0) {
    int A_0 = A_arr[0] / 2;
    rep(i, N) {
      int A_i = A_arr[i];
      if (M > 0 && A_i > A_0) {
        M--;
        A_arr[i] = A_i / 2;
      } else {
        sort(A_arr.begin(), A_arr.end(), std::greater<int>());
        break;
      }
    }
  }
  int answer = 0;
  rep(i, N) { answer += A_arr[i]; }
  cout << answer << endl;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, j) for (long long i = 0; i < j; i++)
#define int long long

using namespace std;

signed main() {
  int N, M, x;
  cin >> N >> M;
  vector<int> A_arr;
  vector<int> A_subarr;
  rep(i, N) {
    cin >> x;
    A_arr.push_back(x);
  }
  sort(A_arr.begin(), A_arr.end(), std::greater<int>());
  int pre_M = M + 1;
  while (M > 0 && pre_M != M) {
    pre_M = M;
    int A_0 = A_arr[0] / 2;
    rep(i, N) {
      int A_i = A_arr[i];
      if (M > 0 && A_i > A_0) {
        M--;
        A_arr[i] = A_i / 2;
      } else {
        sort(A_arr.begin(), A_arr.end(), std::greater<int>());
        break;
      }
    }
  }
  int answer = 0;
  rep(i, N) { answer += A_arr[i]; }
  cout << answer << endl;
}
Problem p02912 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(0);
  cout << setprecision(10) << fixed;
  int n, m;
  cin >> n >> m;
  priority_queue<long long> pq;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    pq.push(x);
  }
  for (int i = 0; i < m; ++i) {
    long long nn = pq.top();
    pq.pop();
    nn /= 2;
    if (nn) {
      pq.push(nn);
    }
  }
  long long ans = 0;
  while (pq.size()) {
    long long nn = pq.top();
    pq.pop();
    ans += nn;
  }
  cout << ans;
  return 0;
}


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

int main() {
  ios::sync_with_stdio(0);
  cout << setprecision(10) << fixed;
  int n, m;
  cin >> n >> m;
  priority_queue<long long> pq;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    pq.push(x);
  }
  for (int i = 0; i < m; ++i) {
    long long nn = pq.top();
    pq.pop();
    nn /= 2;
    pq.push(nn);
  }
  long long ans = 0;
  while (pq.size()) {
    long long nn = pq.top();
    pq.pop();
    ans += nn;
  }
  cout << ans;
  return 0;
}
Problem p02912 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
const ll mod = 1e9 + 7;
const int inf = 1 << 30;

int main() {
  int n, m;
  cin >> n >> m;
  priority_queue<int> q;
  rep(i, n) {
    int a;
    cin >> a;
    q.push(a);
  }
  rep(i, m) {
    int a = q.top();
    a /= 2;
    q.pop();
    q.push(a);
  }
  ll ans = 0;
  rep(i, n) {
    ans += q.top();
    q.pop();
  }
  cout << ans << endl;
}

Fixed submission:
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
const ll mod = 1e9 + 7;
const int inf = 1 << 30;

int main() {
  int n, m;
  cin >> n >> m;
  priority_queue<int> q;
  rep(i, n) {
    int a;
    cin >> a;
    q.push(a);
  }
  rep(i, m) {
    int a = q.top();
    a /= 2;
    q.pop();
    q.push(a);
  }
  ll ans = 0;
  rep(i, n) {
    ans += q.top();
    q.pop();
  }
  cout << ans << endl;
}
Problem p02912 (Python)

Buggy submission (status: Time Limit Exceeded):
N, M = map(int, input().split())
A = list(map(int, input().split()))
while M > 0:
    M -= 1
    A[A.index(max(A))] //= 2
print(sum(A))


Fixed submission:
import heapq

n, m = map(int, input().split())
a = list(map(lambda x: int(x) * (-1), input().split()))
heapq.heapify(a)  # aを優先度付きキューに

for _ in range(m):
    tmp_min = heapq.heappop(a)
    heapq.heappush(a, (-1) * (-tmp_min // 2))  # 計算誤差の関係で-1を2回かけてます
print(-sum(a))
Problem p02912 (Python)

Buggy submission (status: Time Limit Exceeded):
N, M = map(int, input().split())
A = list(map(int, input().split()))

while M > 0:
    max_index = A.index(max(A))
    A[max_index] = A[max_index] // 2
    M -= 1
print(sum(A))


Fixed submission:
N, M = map(int, input().split())
A = list(map(int, input().split()))

while M > 0:
    A.sort(reverse=True)
    if A[0] == 0:
        break
    ham = A[0] // 2
    for i, a in enumerate(A):
        if ham < a and M > 0:
            A[i] = A[i] // 2
            M -= 1
        else:
            break
print(sum(A))
Problem p02912 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(s, i, n) for (int i = (int)s; i < (int)(n); i++)
#define pb push_back
typedef long long ll;

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> a;
  map<ll, ll> mp;
  multiset<ll> ms;
  ll x;
  rep(i, n) {
    cin >> x;
    ms.insert(x);
  }
  ll ans = 0;
  rep(i, m) {
    auto itr = ms.rbegin();
    ms.insert((*itr) / 2);
    ms.erase(*itr);
  }
  for (auto itr = ms.begin(); itr != ms.end(); ++itr) {
    ans += *itr;
  }

  cout << ans << endl;
  return 0;
}

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

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> a;
  map<ll, ll> mp;
  multiset<ll> ms;
  ll x;
  rep(i, n) {
    cin >> x;
    ms.insert(x);
  }
  ll ans = 0;
  rep(i, m) {
    auto itr = ms.rbegin();
    ms.insert((*itr) >> 1);
    ms.erase(ms.find(*itr));
  }
  for (auto itr = ms.begin(); itr != ms.end(); ++itr) {
    ans += *itr;
  }

  cout << ans << endl;
  return 0;
}
Problem p02912 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

int main() {
  int n, m, a;
  cin >> n >> m;
  vector<int> p(n);
  for (int i = 0; i < n; i++) {
    cin >> a;
    p[i] = a;
  }
  sort(p.begin(), p.end());
  for (int i = 0; i < m; i++) {
    p[n - 1] = p[n - 1] / 2;
    sort(p.begin(), p.end());
  }
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    sum += p[i];
  }
  cout << sum;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

int main() {
  int n, m, a;
  cin >> n >> m;
  vector<int> p(n);
  for (int i = 0; i < n; i++) {
    cin >> a;
    p[i] = a;
  }
  sort(p.begin(), p.end(), greater<int>());
  while (true) {
    int half = p[0] / 2;
    for (int i = 0; i < n && m > 0; i++) {
      if (half >= p[i] || p[i] == 0) {
        break;
      }
      p[i] = p[i] / 2;
      m--;
    }
    if (m == 0) {
      break;
    }
    sort(p.begin(), p.end(), greater<int>());
    if (p[0] == 0) {
      break;
    }
  }
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    sum += p[i];
  }
  cout << sum;
  return 0;
}
Problem p02912 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;

int main() {

  int n, m;
  cin >> n >> m;

  priority_queue<long long> que;

  for (int i = 0; i < n; i++) {
    long long ai;
    cin >> ai;
    que.push(ai);
  }

  for (int i = 0; i < m; i++) {
    long long t;
    t = que.top();
    que.pop();
    que.push(t / 2);
  }

  long long ans = 0;
  while (!que.empty()) {
    ans += que.top();
    que.pop();
  }

  cout << ans << endl;
}

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

int main() {

  int n, m;
  cin >> n >> m;

  priority_queue<long long> que;

  for (int i = 0; i < n; i++) {
    long long ai;
    cin >> ai;
    que.push(ai);
  }

  for (int i = 0; i < m; i++) {
    long long t;
    t = que.top();
    que.pop();
    que.push(t / 2);
  }

  long long ans = 0;
  while (!que.empty()) {
    ans += que.top();
    que.pop();
  }

  cout << ans << endl;
}
Problem p02912 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

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[i];
  }
  for (int j = 0; j < M; j++) {
    std::vector<int>::iterator iter = std::max_element(A.begin(), A.end());
    size_t index = std::distance(A.begin(), iter);
    A[index] /= 2;
  }
  long long int sum = 0;
  for (int i = 0; i < N; i++) {
    sum += A[i];
  }
  cout << sum << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

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[i];
  }
  while (M > 0) {
    sort(A.rbegin(), A.rend());
    int mid = A[0] / 2;
    for (int i = 0; i < N; i++) {
      if (M > 0 && A[i] >= mid) {
        A[i] /= 2;
        M--;
      } else {
        break;
      }
    }
  }
  long long int sum = 0;
  for (int i = 0; i < N; i++) {
    sum += A[i];
  }
  cout << sum << endl;
  return 0;
}
Problem p02912 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  priority_queue<int> q;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
  }

  for (int i = 0; i < M; i++) {
    int a = q.top();
    q.pop();
    q.push(a / 2);
  }
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    ans += q.top();
    q.pop();
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  priority_queue<int> q;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    q.push(a);
  }

  for (int i = 0; i < M; i++) {
    int a = q.top();
    q.pop();
    q.push(a / 2);
  }
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    ans += q.top();
    q.pop();
  }
  cout << ans << endl;
  return 0;
}
Problem p02912 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <forward_list>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void) {
  int n, m;
  int i;
  priority_queue<int> a;
  ll ans = 0;

  cin >> n >> m;

  for (i = 0; i < n; i++) {
    int x;
    cin >> x;
    a.push(x);
  }

  for (i = 0; i < m; i++) {
    int k = a.top();

    a.pop();
    a.push(k / 2);
  }

  for (i = 0; i < n;) {
    ans += a.top();
    a.pop();
  }

  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <forward_list>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void) {
  int n, m;
  int i;
  priority_queue<int> a;
  ll ans = 0;

  cin >> n >> m;

  for (i = 0; i < n; i++) {
    int x;
    cin >> x;
    a.push(x);
  }

  for (i = 0; i < m; i++) {
    int k = a.top();

    a.pop();
    a.push(k / 2);
  }

  for (i = 0; i < n; i++) {
    ans += a.top();
    a.pop();
  }

  cout << ans << endl;
}
Problem p02912 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

const int INF = INT_MAX / 2;

int main() {
  int N, M;
  cin >> N >> M;
  priority_queue<int> que;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    que.push(a);
  }

  for (int i = 0; i < M; i++) {
    int mprice = que.top();
    que.pop();
    mprice /= 2;
    if (mprice > 0)
      que.push(mprice);
  }
  long ans = 0;
  while (!que.empty()) {
    ans += que.top();
    que.pop();
  }
  cout << ans << endl;
}

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

const int INF = INT_MAX / 2;

int main() {
  int N, M;
  cin >> N >> M;
  priority_queue<int> que;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    que.push(a);
  }

  for (int i = 0; i < M; i++) {
    int mprice = que.top();
    que.pop();
    que.push(mprice / 2);
  }
  long ans = 0;
  while (!que.empty()) {
    ans += que.top();
    que.pop();
  }
  cout << ans << endl;
}
Problem p02912 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

const int INF = INT_MAX / 2;

int main() {
  int N, M;
  cin >> N >> M;
  priority_queue<int> que;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    que.push(a);
  }

  for (int i = 0; i < M; i++) {
    int mprice = que.top();
    que.pop();
    mprice /= 2;
    if (mprice != 0)
      que.push(mprice);
  }
  long ans = 0;
  while (!que.empty()) {
    ans += que.top();
    que.pop();
  }
  cout << ans << endl;
}

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

const int INF = INT_MAX / 2;

int main() {
  int N, M;
  cin >> N >> M;
  priority_queue<int> que;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    que.push(a);
  }

  for (int i = 0; i < M; i++) {
    int mprice = que.top();
    que.pop();
    mprice /= 2;
    que.push(mprice);
  }
  long ans = 0;
  while (!que.empty()) {
    ans += que.top();
    que.pop();
  }
  cout << ans << endl;
}
Problem p02912 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _GLIBCXX_DEBUG
#include <algorithm>
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod = 1e+9 + 7;

int main() {
  ll n, m;
  cin >> n >> m;
  priority_queue<ll> q;
  rep(i, n) {
    ll a;
    cin >> a;
    q.push(a);
  }
  rep(i, m) {
    ll t = q.top();
    q.pop();
    q.push(t / 2);
  }
  ll sum = 0;
  while (!q.empty()) {
    sum += q.top();
    q.pop();
  }
  cout << sum << endl;
}


Fixed submission:
// #define _GLIBCXX_DEBUG
#include <algorithm>
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod = 1e+9 + 7;

int main() {
  ll n, m;
  cin >> n >> m;
  priority_queue<ll> q;
  rep(i, n) {
    ll a;
    cin >> a;
    q.push(a);
  }
  rep(i, m) {
    ll t = q.top();
    q.pop();
    q.push(t / 2);
  }
  ll sum = 0;
  while (!q.empty()) {
    sum += q.top();
    q.pop();
  }
  cout << sum << endl;
}