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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
using namespace std;

typedef long long ll;
#define rep(i, N) for (ll(i) = 0; (i) < (N); (i)++)

const int mod = 1000000007;

int main() {
  ll n, k;
  cin >> n >> k;

  vector<ll> h(n);
  rep(i, n) { cin >> h[i]; }

  sort(h.begin(), h.end());
  reverse(h.begin(), h.end());
  ll ans = 0;
  for (int i = 0; i < k || i < n; ++i)
    h[i] = 0;
  rep(i, n) ans += h[i];
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
using namespace std;

typedef long long ll;
#define rep(i, N) for (ll(i) = 0; (i) < (N); (i)++)

const int mod = 1000000007;

int main() {
  ll n, k;
  cin >> n >> k;

  vector<ll> h(n);
  rep(i, n) { cin >> h[i]; }

  sort(h.begin(), h.end());
  reverse(h.begin(), h.end());
  ll ans = 0;
  for (int i = 0; i < k && i < n; ++i)
    h[i] = 0;
  rep(i, n) ans += h[i];
  cout << ans << endl;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int, int>::iterator
#define sit set<int>::iterator
#define itrm(g, x) for (mit g = x.begin(); g != x.end(); g++)
#define itrs(g, x) for (sit g = x.begin(); g != x.end(); g++)
#define ltype int
#define rep(i, j, k) for (ltype(i) = (j); (i) <= (k); (i)++)
#define rap(i, j, k) for (ltype(i) = (j); (i) < (k); (i)++)
#define per(i, j, k) for (ltype(i) = (j); (i) >= (k); (i)--)
#define pii pair<int, int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
const int inf = 0x3f3f3f3f, mod = 1000000007;
const double pi = 3.1415926535897932, eps = 1e-6;
int n, k, a[100005];
ll ans;
int main() {
  scanf("%d%d", &n, &k);
  rep(i, 1, n) scanf("%d", a + i);
  sort(a + 1, a + n + 1);
  reverse(a + 1, a + n + 1);
  rep(i, k + 1, n) ans += a[i];
  printf("%lld\n", ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int, int>::iterator
#define sit set<int>::iterator
#define itrm(g, x) for (mit g = x.begin(); g != x.end(); g++)
#define itrs(g, x) for (sit g = x.begin(); g != x.end(); g++)
#define ltype int
#define rep(i, j, k) for (ltype(i) = (j); (i) <= (k); (i)++)
#define rap(i, j, k) for (ltype(i) = (j); (i) < (k); (i)++)
#define per(i, j, k) for (ltype(i) = (j); (i) >= (k); (i)--)
#define pii pair<int, int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
const int inf = 0x3f3f3f3f, mod = 1000000007;
const double pi = 3.1415926535897932, eps = 1e-6;
int n, k, a[200005];
ll ans;
int main() {
  scanf("%d%d", &n, &k);
  rep(i, 1, n) scanf("%d", a + i);
  sort(a + 1, a + n + 1);
  reverse(a + 1, a + n + 1);
  rep(i, k + 1, n) ans += a[i];
  printf("%lld\n", ans);
  return 0;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define lol long long
using namespace std;
lol m[100000];
int main() {
  lol a, b, c, ans = 0;
  string s;
  cin >> a >> b;
  for (int i = 0; i < a; i++) {
    cin >> m[i];
  }
  sort(m, m + a, greater<lol>());
  for (int i = b; i < a; i++) {
    ans += m[i];
  }
  cout << ans << "\n";
  return (0);
}


Fixed submission:
#include <bits/stdc++.h>
#define lol long long
using namespace std;
lol m[200005];
int main() {
  lol a, b, c, ans = 0;
  string s;
  cin >> a >> b;
  for (int i = 0; i < a; i++) {
    cin >> m[i];
  }
  sort(m, m + a, greater<lol>());
  for (int i = b; i < a; i++) {
    ans += m[i];
  }
  cout << ans << "\n";
  return (0);
}
Problem p02785 (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 all(a) (a).begin(), (a).end()
typedef long long ll;

int main(void) {
  int n, k;
  cin >> n >> k;
  vector<ll> h(n);
  rep(i, n) cin >> h[i];
  sort(all(h));
  cout << accumulate(h.begin(), h.begin() + n - k, 0LL) << 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 all(a) (a).begin(), (a).end()
typedef long long ll;

int main(void) {
  int n, k;
  cin >> n >> k;
  vector<ll> h(n);
  rep(i, n) cin >> h[i];
  sort(all(h));
  ll sum = 0;
  rep(i, n - k) sum += h[i];
  cout << sum << endl;
  return 0;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
// 素因数分解
typedef pair<long long, long long> P;
vector<P> prime_factorize(long long n) {
  vector<P> res;
  for (long long p = 2; p * p <= n; ++p) {
    if (n % p != 0)
      continue;
    int num = 0;
    while (n % p == 0) {
      ++num;
      n /= p;
    }
    res.push_back(make_pair(p, num));
  }
  if (n != 1)
    res.push_back(make_pair(n, 1));
  return res;
}
// 因数分解
long long gcd(long long x, long long y) {
  if (y == 0) {
    return x;
  } else {
    return gcd(y, x % y);
  }
}
const int MOD = 1000000007;
typedef long long int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (n); i++)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> H(n);
  rep(i, n) { cin >> H[i]; }
  sort(H.begin(), H.end());
  for (ll i = 0; i < k; i++) {
    H[n - 1 - i] = 0;
  }
  ll ans = 0;
  rep(i, n) { ans += H[i]; }
  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
// 素因数分解
typedef pair<long long, long long> P;
vector<P> prime_factorize(long long n) {
  vector<P> res;
  for (long long p = 2; p * p <= n; ++p) {
    if (n % p != 0)
      continue;
    int num = 0;
    while (n % p == 0) {
      ++num;
      n /= p;
    }
    res.push_back(make_pair(p, num));
  }
  if (n != 1)
    res.push_back(make_pair(n, 1));
  return res;
}
// 因数分解
long long gcd(long long x, long long y) {
  if (y == 0) {
    return x;
  } else {
    return gcd(y, x % y);
  }
}
const int MOD = 1000000007;
typedef long long int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (n); i++)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> H(n);
  rep(i, n) { cin >> H[i]; }
  sort(H.begin(), H.end());
  for (ll i = 0; i < k && i <= n - 1; i++) {
    H[n - 1 - i] = 0;
  }
  ll ans = 0;
  rep(i, n) { ans += H[i]; }
  cout << ans << endl;

  return 0;
}
Problem p02785 (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 REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)

using ll = long long;

int main() {
  int N, K;
  cin >> N >> K;
  vector<long long int> H(N + 1);
  rep(i, N) { cin >> H[i]; }

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

  long long int atksum = 0;
  for (vector<long long int>::iterator itr = H.begin(), e = H.end();
       itr != e - K; itr++) {
    atksum += *itr;
  }
  cout << atksum << endl;
}

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

using ll = long long;

int main() {
  int N, K;
  cin >> N >> K;
  vector<long long int> H(N + 1);
  rep(i, N) { cin >> H[i]; }

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

  long long int atksum = 0;
  for (int i = 0; i < N - K + 1; i++) {
    atksum += H[i];
  }
  cout << atksum << endl;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll int arr[100005];
int main() {
  ll int j, i, m, n, sum = 0;
  cin >> m >> n;
  if (n >= m) {
    while (m--)
      cin >> n;
    cout << 0 << endl;
    exit(0);
  }
  for (i = 0; i < m; i++) {
    cin >> arr[i];
    sum += arr[i];
  }
  if (!n) {
    cout << sum << endl;
    exit(0);
  }
  sort(arr, arr + i);
  for (j = 0; j <= n; j++, i--)
    sum -= arr[i];
  cout << sum << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll int arr[200005];

int main() {
  ll int j, i, m, n, sum = 0;
  cin >> m >> n;
  if (n >= m) {
    while (m--)
      cin >> n;
    cout << 0 << endl;
    exit(0);
  }
  for (i = 0; i < m; i++) {
    cin >> arr[i];
    sum += arr[i];
  }
  if (!n) {
    cout << sum << endl;
    exit(0);
  }
  sort(arr, arr + i);
  for (j = 0; j <= n; j++, i--)
    sum -= arr[i];
  cout << sum << endl;
  return 0;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
// Yazar: Mehmet Kutay Bozkurt
// Auther: Mehmet Kutay bozkurt
//  #include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
typedef long long int lo;
#define pb push_back
#define st first
#define nd second
lo a, b, c, d, e, n, m, x, y, z, a1[100005], a2[100005], k, t;
char c1, c2, c3, c4;
string s1, s2, s3, s4, den[3];
bool av = false;
map<char, lo> mp;
vector<lo> v;
vector<lo> v1;
int main() {
  // freopen("gir.gir","r",stdin);
  // freopen("cik.cik","w",stdout);
  cin >> n >> m;
  for (lo i = 0; i < n; i++) {
    cin >> a1[i];
  }
  x = 0;
  sort(a1, a1 + n);
  for (lo i = 0; i < n - m; i++) {
    x += a1[i];
  }
  cout << x << endl;
  return 0;
}

Fixed submission:
// Yazar: Mehmet Kutay Bozkurt
// Auther: Mehmet Kutay bozkurt
//  #include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
typedef long long int lo;
#define pb push_back
#define st first
#define nd second
lo a, b, c, d, e, n, m, x, y, z, a1[500005], a2[100005], k, t;
char c1, c2, c3, c4;
string s1, s2, s3, s4, den[3];
bool av = false;
map<char, lo> mp;
vector<lo> v;
vector<lo> v1;
int main() {
  // freopen("gir.gir","r",stdin);
  // freopen("cik.cik","w",stdout);
  cin >> n >> m;
  for (lo i = 0; i < n; i++) {
    cin >> a1[i];
  }
  x = 0;
  sort(a1, a1 + n);
  for (lo i = 0; i < n - m; i++) {
    x += a1[i];
  }
  cout << x << endl;
  return 0;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5 + 5;
int n, m, val[N];
ll sum;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i)
    cin >> val[i];
  sort(val + 1, val + 1 + n);
  for (int i = 1; i <= n - m; ++i)
    sum += val[i];
  cout << sum;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5;
int n, m, val[N];
ll sum;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i)
    cin >> val[i];
  sort(val + 1, val + 1 + n);
  for (int i = 1; i <= n - m; ++i)
    sum += val[i];
  cout << sum;
  return 0;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#ifdef XVENOM
#define errp(...) fprintf(stderr, __VA_ARGS__)
#define dbg(...) errp("[%s]: ", #__VA_ARGS__), dbg_str(__VA_ARGS__)
#else
#define errp(...)
#define dbg(...)
#endif
template <typename U, typename V> string to_string(pair<U, V>);
string to_string(const string &e_) { return "\"" + e_ + "\""; }
string to_string(char e_) { return "\'" + string(1, e_) + "\'"; }
string to_string(bool e_) { return e_ ? "true" : "false"; }
template <typename T> string to_string(T e_) {
  string s_ = "[ ";
  for (const auto &x_ : e_)
    s_ += to_string(x_) + " ";
  return s_ + "]";
}
template <typename U, typename V> string to_string(pair<U, V> e_) {
  return "(" + to_string(e_.first) + ", " + to_string(e_.second) + ")";
}
void dbg_str() { errp(" \n"); }
template <typename U, typename... V> void dbg_str(U u, V... v) {
  errp(" %s", to_string(u).c_str());
  dbg_str(v...);
}
/* --- */
const int N = 100010;
int a[N];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  /* --- */
  int n, k;
  cin >> n >> k;

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

  sort(a, a + n);
  ll ans = 0;

  for (int i = 0; i < n - k; i++)
    ans += a[i];

  cout << ans;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#ifdef XVENOM
#define errp(...) fprintf(stderr, __VA_ARGS__)
#define dbg(...) errp("[%s]: ", #__VA_ARGS__), dbg_str(__VA_ARGS__)
#else
#define errp(...)
#define dbg(...)
#endif
template <typename U, typename V> string to_string(pair<U, V>);
string to_string(const string &e_) { return "\"" + e_ + "\""; }
string to_string(char e_) { return "\'" + string(1, e_) + "\'"; }
string to_string(bool e_) { return e_ ? "true" : "false"; }
template <typename T> string to_string(T e_) {
  string s_ = "[ ";
  for (const auto &x_ : e_)
    s_ += to_string(x_) + " ";
  return s_ + "]";
}
template <typename U, typename V> string to_string(pair<U, V> e_) {
  return "(" + to_string(e_.first) + ", " + to_string(e_.second) + ")";
}
void dbg_str() { errp(" \n"); }
template <typename U, typename... V> void dbg_str(U u, V... v) {
  errp(" %s", to_string(u).c_str());
  dbg_str(v...);
}
/* --- */
const int N = 200010;
ll a[N];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  /* --- */
  int n, k;
  cin >> n >> k;

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

  sort(a, a + n);
  ll ans = 0;

  for (int i = 0; i < n - k; i++)
    ans += a[i];

  cout << ans;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <stdio.h>
#include <vector>
using namespace std;
#define int long long
#define rep(s, i, n) for (int i = s; i < n; i++)
#define c(n) cout << n << endl;
#define ic(n)                                                                  \
  int n;                                                                       \
  cin >> n;
#define sc(s)                                                                  \
  string s;                                                                    \
  cin >> s;
#define mod 1000000007
#define inf 1000000000000000007
#define f first
#define s second
#define mini(c, a, b) *min_element(c + a, c + b)
#define maxi(c, a, b) *max_element(c + a, c + b)
int keta(int x) {
  rep(0, i, 30) {
    if (x < 10) {
      return i + 1;
    }
    x = x / 10;
  }
}
int gcd(int x, int y) {
  int aa = x, bb = y;
  rep(0, i, 1000) {
    aa = aa % bb;
    if (aa == 0) {
      return bb;
    }
    bb = bb % aa;
    if (bb == 0) {
      return aa;
    }
  }
}
int lcm(int x, int y) {
  int aa = x, bb = y;
  rep(0, i, 1000) {
    aa = aa % bb;
    if (aa == 0) {
      return x / bb * y;
    }
    bb = bb % aa;
    if (bb == 0) {
      return x / aa * y;
    }
  }
}
char mem[114514];
char t[114514];
char c[114514];
string s[114514];
int a[114514], b[114514];
signed main() {
  ic(n) ic(x) int sum = 0;
  rep(0, i, n) cin >> a[i];
  sort(a, a + n);
  rep(0, i, n - x) sum += a[i];
  c(sum)
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <stdio.h>
#include <vector>
using namespace std;
#define int long long
#define rep(s, i, n) for (int i = s; i < n; i++)
#define c(n) cout << n << endl;
#define ic(n)                                                                  \
  int n;                                                                       \
  cin >> n;
#define sc(s)                                                                  \
  string s;                                                                    \
  cin >> s;
#define mod 1000000007
#define inf 1000000000000000007
#define f first
#define s second
#define mini(c, a, b) *min_element(c + a, c + b)
#define maxi(c, a, b) *max_element(c + a, c + b)
int keta(int x) {
  rep(0, i, 30) {
    if (x < 10) {
      return i + 1;
    }
    x = x / 10;
  }
}
int gcd(int x, int y) {
  int aa = x, bb = y;
  rep(0, i, 1000) {
    aa = aa % bb;
    if (aa == 0) {
      return bb;
    }
    bb = bb % aa;
    if (bb == 0) {
      return aa;
    }
  }
}
int lcm(int x, int y) {
  int aa = x, bb = y;
  rep(0, i, 1000) {
    aa = aa % bb;
    if (aa == 0) {
      return x / bb * y;
    }
    bb = bb % aa;
    if (bb == 0) {
      return x / aa * y;
    }
  }
}
char mem[114514];
char t[114514];
char c[114514];
string s[114514];
int a[214514], b[114514];
signed main() {
  ic(n) ic(x) int sum = 0;
  rep(0, i, n) cin >> a[i];
  sort(a, a + n);
  rep(0, i, n - x) sum += a[i];
  c(sum)
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <assert.h>
#include <iostream>
using I = long long int;
using namespace std;
int H[30001];
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  I n, k;
  cin >> n >> k;
  for (int i = 0; i < n; ++i)
    cin >> H[i];
  sort(H, H + n);
  // for(int i = 0; i < n; ++ i) cout << H[i] << " ";

  I tot = 0;
  const int start = n - (k + 1); // cout << "start: " << start << "\n";
  for (int i = start; i >= 0; i--) {
    tot += H[i];
  }
  cout << tot;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <assert.h>
#include <iostream>
using I = long long int;
using namespace std;
int H[300001];
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  I n, k;
  cin >> n >> k;
  for (int i = 0; i < n; ++i)
    cin >> H[i];
  sort(H, H + n);
  // for(int i = 0; i < n; ++ i) cout << H[i] << " ";

  I tot = 0;
  const int start = n - (k + 1); // cout << "start: " << start << "\n";
  for (int i = start; i >= 0; i--) {
    tot += H[i];
  }
  cout << tot;
  return 0;
}
Problem p02785 (C++)

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

int main() {
  int N, K;
  cin >> N >> K;
  ll H[200010];
  ll attack_cnt = 0;

  for (int i = 0; i < N; ++i)
    cin >> H[i];

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

  for (int i = 0; i < N - K; ++i) {
    attack_cnt += H[i];
  }

  cout << attack_cnt << endl;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  ll H[200010];
  ll attack_cnt = 0;

  for (int i = 0; i < N; ++i)
    cin >> H[i];

  stable_sort(H, H + N);

  for (int i = 0; i < N - K; ++i) {
    attack_cnt += H[i];
  }

  cout << attack_cnt << endl;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>
#define inf 0x3f3f3f3f
#define ll long long
using namespace std;
const int maxn = 1e5 + 5;
ll a[maxn];

int main() {
  ll n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  sort(a + 1, a + n + 1);
  ll sum = 0;
  for (int i = 1; i <= n - k; i++)
    sum += a[i];
  cout << sum << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>
#define inf 0x3f3f3f3f
#define ll long long
using namespace std;
const int maxn = 2e5 + 5;
ll a[maxn];

int main() {
  ll n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  sort(a + 1, a + n + 1);
  ll sum = 0;
  for (int i = 1; i <= n - k; i++)
    sum += a[i];
  cout << sum << endl;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>

using namespace std;

int n, k;
long long ans;
int a[20005];
int cmp(int a, int b) { return a > b; }
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  sort(a + 1, a + 1 + n, cmp);
  for (int i = 1; i <= n; i++) {
    if (i > k)
      ans += a[i];
  }
  printf("%lld", ans);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>

using namespace std;

int n, k;
long long ans;
int a[200005];
int cmp(int a, int b) { return a > b; }
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  sort(a + 1, a + 1 + n, cmp);
  for (int i = 1; i <= n; i++) {
    if (i > k)
      ans += a[i];
  }
  printf("%lld", ans);
  return 0;
}
Problem p02785 (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;
typedef long long ll;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int n, k;
  cin >> n >> k;
  vector<long long int> h(n);
  rep(i, n) cin >> h[i];
  if (n <= k)
    cout << 0 << endl;
  else if (k == 0)
    cout << accumulate(h.begin(), h.end(), 0LL) << endl;
  else {
    rep(i, k) {
      auto iter = max_element(h.begin(), h.end());
      h.erase(iter);
    }
    cout << accumulate(h.begin(), h.end(), 0LL) << endl;
  }
}

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

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int n, k;
  cin >> n >> k;
  vector<long long int> h(n);
  rep(i, n) cin >> h[i];
  if (n <= k)
    cout << 0 << endl;
  else if (k == 0)
    cout << accumulate(h.begin(), h.end(), 0LL) << endl;
  else {
    sort(h.begin(), h.end(), greater<int>());
    h.erase(h.begin(), h.begin() + k);
    cout << accumulate(h.begin(), h.end(), 0LL) << endl;
  }
}
Problem p02785 (C++)

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

#define ll long long
#define vi vector<int>

using namespace std;

int n, k, a[100001];
ll cnt;

int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n - k; i++) {
    cnt += a[i];
  }
  cout << cnt;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

#define ll long long
#define vi vector<int>

using namespace std;

int n, k, a[1000001];
ll cnt;

int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n - k; i++) {
    cnt += a[i];
  }
  cout << cnt;
  return 0;
}
Problem p02785 (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 rep1(i, n) for (int i = 1; i < (int)(n); i++)
typedef long long ll;

int main() {
  ll n, k;
  cin >> n >> k;
  ll sum = 0;
  vector<ll> H(n);
  rep(i, n) {
    cin >> H[i];
    sum += H[i];
  }
  sort(H.rbegin(), H.rend());

  rep(i, k) { sum -= H[i]; }
  if (sum <= 0)
    cout << 0 << endl;
  else
    cout << sum << endl;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
typedef long long ll;

int main() {
  ll n, k;
  cin >> n >> k;
  ll sum = 0;
  vector<ll> H(n);
  rep(i, n) {
    cin >> H[i];
    sum += H[i];
  }
  sort(H.rbegin(), H.rend());

  rep(i, k) {
    sum -= H[i];
    if (sum < 0)
      break;
  }
  if (sum <= 0)
    cout << 0 << endl;
  else
    cout << sum << endl;
}
Problem p02785 (C++)

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

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> H(N);
  rep(i, N) cin >> H[i];
  sort(H.begin(), H.end(), greater<ll>());
  rep(i, K) H[i] = 0;
  ll ans = 0;
  rep(i, N) {
    if (H[i] > 0) {
      ans += H[i];
      H[i] = 0;
    }
  }
  cout << ans << endl;

  return 0;
}

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

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> H(N);
  rep(i, N) cin >> H[i];
  sort(H.begin(), H.end(), greater<ll>());
  rep(i, K) if (i < N) H[i] = 0;
  ll ans = 0;
  rep(i, N) {
    if (H[i] > 0) {
      ans += H[i];
      H[i] = 0;
    }
  }
  cout << ans << endl;

  return 0;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define INF 1000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X)                                                                 \
  {}
#define ARDEB(i, X)                                                            \
  {}
#define END                                                                    \
  {}
#endif
typedef long long ll;
typedef pair<int, int> P;
struct edge {
  int to, cost;
};
using namespace std;

int n, m, ans;
int a[111111];
signed main() {
  cin >> n >> m;
  rep(i, n) cin >> a[i];
  sort(a, a + n, greater<>());
  rep(i, n) {
    if (m != 0) {
      m--;
    } else {
      ans += a[i];
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define INF 1000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X)                                                                 \
  {}
#define ARDEB(i, X)                                                            \
  {}
#define END                                                                    \
  {}
#endif
typedef long long ll;
typedef pair<int, int> P;
struct edge {
  int to, cost;
};
using namespace std;

int n, m, ans;
int a[211111];
signed main() {
  cin >> n >> m;
  rep(i, n) cin >> a[i];
  sort(a, a + n, greater<>());
  rep(i, n) {
    if (m != 0) {
      m--;
    } else {
      ans += a[i];
    }
  }
  cout << ans << endl;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define LL long long
using namespace std;
inline int read() {
  int x = 0;
  char c = getchar();
  while (!isdigit(c))
    c = getchar();
  while (isdigit(c))
    x = x * 10 + c - '0', c = getchar();
  return x;
}
template <typename T> void read(T &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  x *= f;
}
inline void write(int x) {
  if (x > 9)
    write(x / 10);
  putchar(x % 10 + '0');
}
int n, a[100050], k;
LL sum;
int main() {
  int i;
  read(n), read(k);
  if (n <= k) {
    cout << 0 << endl;
    return 0;
  }
  for (i = 1; i <= n; ++i)
    read(a[i]);
  sort(a + 1, a + n + 1);
  n -= k;
  sum = 0;
  for (i = 1; i <= n; ++i)
    sum += a[i];
  cout << sum << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define LL long long
using namespace std;
inline int read() {
  int x = 0;
  char c = getchar();
  while (!isdigit(c))
    c = getchar();
  while (isdigit(c))
    x = x * 10 + c - '0', c = getchar();
  return x;
}
template <typename T> void read(T &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  x *= f;
}
inline void write(int x) {
  if (x > 9)
    write(x / 10);
  putchar(x % 10 + '0');
}
int n, a[200050], k;
LL sum;
int main() {
  int i;
  read(n), read(k);
  if (n <= k) {
    cout << 0 << endl;
    return 0;
  }
  for (i = 1; i <= n; ++i)
    read(a[i]);
  sort(a + 1, a + n + 1);
  n -= k;
  sum = 0;
  for (i = 1; i <= n; ++i)
    sum += a[i];
  cout << sum << endl;
  return 0;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll; // long longをllとして簡略

int main() {
  ll n, k;
  ll ans = 0;
  cin >> n >> k;   // monster_no,deathblow_no
  vector<ll> h(n); // monster hp
  rep(i, n) { cin >> h[i]; }
  sort(h.rbegin(), h.rend());
  rep(i, k) { h[i] = 0; }
  rep(i, n) { ans += h[i]; }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll; // long longをllとして簡略

int main() {
  ll n, k;
  ll ans = 0;
  cin >> n >> k;   // monster_no,deathblow_no
  vector<ll> h(n); // monster hp
  rep(i, n) { cin >> h[i]; }
  sort(h.rbegin(), h.rend());
  rep(i, k) {
    h[i] = 0;
    if (n == i) {
      cout << ans << endl;
      return 0;
    }
  }
  rep(i, n) { ans += h[i]; }
  cout << ans << endl;
  return 0;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define MAX(a, b) a = a > b ? a : b
#define MIN(a, b) a = a > b ? a : b
#define REP(i, x, n) for (int i = x; i < n; i++)
#define REPR(i, x, n) for (int i = x - 1; i >= ; i--)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLr(obj) (obj).rbegin(), (obj).rend()
#define endl "\n"
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;

int main() {
  ll h, n, ans = 0;
  cin >> n >> h;
  ll a[101010];
  rep(i, n) { cin >> a[i]; }
  sort(a, a + n);
  repr(i, n - h) { ans += a[i]; }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define MAX(a, b) a = a > b ? a : b
#define MIN(a, b) a = a > b ? a : b
#define REP(i, x, n) for (int i = x; i < n; i++)
#define REPR(i, x, n) for (int i = x - 1; i >= ; i--)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLr(obj) (obj).rbegin(), (obj).rend()
#define endl "\n"
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;

int main() {
  ll h, n, ans = 0;
  cin >> n >> h;
  ll a[201010];
  rep(i, n) { cin >> a[i]; }
  sort(a, a + n);
  repr(i, n - h) { ans += a[i]; }
  cout << ans << endl;
}
Problem p02785 (Python)

Buggy submission (status: Time Limit Exceeded):
N, K = map(int, input().split())
H = [int(N) for N in input().split()]
for i in range(0, K):
    if H[H.index(max(H))] == 0:
        break
    H[H.index(max(H))] = 0
print(sum(filter(lambda x: x != 0, H)))


Fixed submission:
N, K = map(int, input().split())
H = [int(N) for N in input().split()]
H.sort(reverse=True)
if N <= K:
    print(0)
else:
    for i in range(0, K):
        H[i] = 0
    print(sum(H))
Problem p02785 (Python)

Buggy submission (status: Runtime Error):
N, K = map(int, input().split())
H = map(int, input().split())

H.sort(reverse=True)

if K >= N:
    print(0)
else:
    print(sum(H[K:]))


Fixed submission:
N, K = map(int, input().split())
H = list(map(int, input().split()))

H.sort(reverse=True)

if K >= N:
    print(0)
else:
    print(sum(H[K:]))
Problem p02785 (Python)

Buggy submission (status: Time Limit Exceeded):
n, k = map(int, input().split())
h = sorted(map(int, input().split()), reverse=True)
if k == 0:
    print(sum(h))
elif k < n:
    for i in range(k):
        h.pop(0)
    print(sum(h))
else:
    print(0)


Fixed submission:
n, k = map(int, input().split())
h = sorted(map(int, input().split()), reverse=True)
if k == 0:
    print(sum(h))
elif k < n:
    print(sum(h[k:]))
else:
    print(0)
Problem p02785 (Python)

Buggy submission (status: Runtime Error):
H, K = map(int, input().split())
hp = list(int, map(input().split()))
hp.sort(reverse=True)
print(sum(hp[K:]))


Fixed submission:
H, K = map(int, input().split())
hp = list(map(int, input().split()))
hp.sort(reverse=True)
print(sum(hp[K:]))
Problem p02785 (Python)

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

H_sorted = sorted(H, reverse=True)

for _ in range(K):
    if not len(H_sorted):
        break
    H_sorted.pop(0)

print(sum(H_sorted))


Fixed submission:
N, K = map(int, input().split())
H = list(map(int, input().split()))

H_sorted = sorted(H, reverse=True)

print(sum(H_sorted[K:]))
Problem p02785 (Python)

Buggy submission (status: Time Limit Exceeded):
import sys

n, k = map(int, input().split())
hp_list = list(map(int, input().split()))
hp_list.sort(reverse=True)

if k >= len(hp_list):
    print(0)
    sys.exit()

for del_num in range(k):
    del hp_list[0]
print(sum(hp_list))


Fixed submission:
import sys

n, k = map(int, input().split())
hp_list = list(map(int, input().split()))
hp_list.sort(reverse=True)

if k >= len(hp_list):
    print(0)
    sys.exit()

hp_list = hp_list[k:]
print(sum(hp_list))
Problem p02785 (C++)

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

long long n, m, sumv = 0;
long long mon[100005];

long long cmp(long long a, long long b) { return a < b; }

int main() {
  cin >> n >> m;
  for (long long i = 1; i <= n; i++)
    cin >> mon[i];
  if (n <= m) {
    cout << 0 << endl;
    return 0;
  }
  sort(mon + 1, mon + n + 1, cmp);
  for (long long i = 1; i <= n - m; i++)
    sumv += mon[i];
  cout << sumv << endl;
  return 0;
}

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

long long n, m, sumv = 0;
long long mon[200005];

long long cmp(long long a, long long b) { return a < b; }

int main() {
  cin >> n >> m;
  for (long long i = 1; i <= n; i++)
    cin >> mon[i];
  if (n <= m) {
    cout << 0 << endl;
    return 0;
  }
  sort(mon + 1, mon + n + 1, cmp);
  for (long long i = 1; i <= n - m; i++)
    sumv += mon[i];
  cout << sumv << endl;
  return 0;
}
Problem p02785 (Python)

Buggy submission (status: Runtime Error):
n, k = map(int, input().split())
h = list(map(int, input().split()))
h.sort()
for i in range(k):
    h.pop()
print(sum(h))


Fixed submission:
n, k = map(int, input().split())
h = list(map(int, input().split()))
if n <= k:
    print(0)
    exit()
h.sort()
for i in range(k):
    h.pop()
print(sum(h))
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>
#define int long long
#define mod (int)(1000000007)
using namespace std;
int test[123456];
signed main() {
  int n, m, a, b = 0, ans = 0;
  cin >> n >> m;
  for (int h = 0; h < n; h++) {
    cin >> test[h];
  }
  sort(test, test + n);
  for (int h = 0; h < n - m; h++) {
    ans += test[h];
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>
#define int long long
#define mod (int)(1000000007)
using namespace std;
int test[213456];
signed main() {
  int n, m, a, b = 0, ans = 0;
  cin >> n >> m;
  for (int h = 0; h < n; h++) {
    cin >> test[h];
  }
  sort(test, test + n);
  for (int h = 0; h < n - m; h++) {
    ans += test[h];
  }
  cout << ans << endl;
}
Problem p02785 (C++)

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

ll num[sz];

int main() {

  ll n, k, i, j, a, b, x, c, d;

  cin >> n >> k;

  for (i = 1; i <= n; i++) {
    cin >> num[i];
  }

  sort(num + 1, num + n + 1);

  c = 0;

  for (i = n; i >= 1; i--) {
    if (k > 0)
      k--;
    else {
      c += num[i];
    }
  }

  cout << c << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long int
#define sz 200010
using namespace std;

ll num[sz];

int main() {

  ll n, k, i, j, a, b, x, c, d;

  cin >> n >> k;

  for (i = 1; i <= n; i++) {
    cin >> num[i];
  }

  sort(num + 1, num + n + 1);

  c = 0;

  for (i = n; i >= 1; i--) {
    if (k > 0)
      k--;
    else {
      c += num[i];
    }
  }

  cout << c << endl;

  return 0;
}
Problem p02785 (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 ll long long

int main() {
  int N, K;
  cin >> N >> K;
  vector<ll> monhp(N);
  rep(i, N) { cin >> monhp.at(i); }
  stable_sort(monhp.begin(), monhp.end(), greater<ll>());
  if (K != 0) {
    vector<ll> hissatu(K);
    copy(monhp.begin(), monhp.begin() + K, hissatu.begin());
    cout << accumulate(monhp.begin(), monhp.end(), 0LL) -
                accumulate(hissatu.begin(), hissatu.end(), 0LL)
         << endl;
  } else {
    cout << accumulate(monhp.begin(), monhp.end(), 0LL) << endl;
  }
}


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

int main() {
  int N, K;
  cin >> N >> K;
  vector<ll> monhp(N);
  rep(i, N) { cin >> monhp.at(i); }
  stable_sort(monhp.begin(), monhp.end(), greater<ll>());
  if (K != 0) {
    int num = min(K, N);
    vector<ll> hissatu(num);
    copy(monhp.begin(), monhp.begin() + num, hissatu.begin());
    cout << accumulate(monhp.begin(), monhp.end(), 0LL) -
                accumulate(hissatu.begin(), hissatu.end(), 0LL)
         << endl;
  } else {
    cout << accumulate(monhp.begin(), monhp.end(), 0LL) << endl;
  }
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;

#define LL unsigned long long int
#define SZ 110

int g[SZ];

int mex(set<int> &grnd) {
  int i = 0;
  for (const int &x : grnd) {
    if (x != i)
      return i;
    i++;
  }
  return i;
}

int grundy(int n) {
  if (g[n] != -1)
    return g[n];
  if (n < 2)
    return g[n] = 0;

  set<int> grnd;

  for (int i = 1; i <= n; i++)
    if (n % (n - i) == 0)
      grnd.insert(grundy(n - i));

  return g[n] = mex(grnd);
}

int result(int n, int m) {
  int jor = 0;

  if (n & 1)
    jor = grundy(m);

  return jor;
}

int towerBreakers(int n, int m) {
  if (result(n, m))
    return 1;
  return 2;
}

int main() {
  //    freopen("in.txt", "r", stdin);
  //    freopen("out.txt", "w", stdout);
  LL n, a, k, i, sum = 0, d;
  vector<int> h;

  cin >> n >> k;
  for (i = 0; i < n; i++) {
    cin >> d;
    h.push_back(d);
  }
  sort(h.begin(), h.end());
  k = n - k;
  for (i = 0; i < k; i++)
    sum += h[i];
  cout << sum << endl;

  return 0;
}
/**
2
2 2
1 4

*/


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;

#define LL unsigned long long int
#define SZ 110

int g[SZ];

int mex(set<int> &grnd) {
  int i = 0;
  for (const int &x : grnd) {
    if (x != i)
      return i;
    i++;
  }
  return i;
}

int grundy(int n) {
  if (g[n] != -1)
    return g[n];
  if (n < 2)
    return g[n] = 0;

  set<int> grnd;

  for (int i = 1; i <= n; i++)
    if (n % (n - i) == 0)
      grnd.insert(grundy(n - i));

  return g[n] = mex(grnd);
}

int result(int n, int m) {
  int jor = 0;

  if (n & 1)
    jor = grundy(m);

  return jor;
}

int towerBreakers(int n, int m) {
  if (result(n, m))
    return 1;
  return 2;
}

int main() {
  //    freopen("in.txt", "r", stdin);
  //    freopen("out.txt", "w", stdout);
  LL n, a, k, i, sum = 0, d;
  vector<int> h;

  cin >> n >> k;
  for (i = 0; i < n; i++) {
    cin >> d;
    h.push_back(d);
  }
  if (k >= n) {
    puts("0");
    return 0;
  }
  sort(h.begin(), h.end());
  k = n - k;
  for (i = 0; i < k; i++)
    sum += h[i];
  cout << sum << endl;

  return 0;
}
/**
2
2 2
1 4

*/
Problem p02785 (C++)

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<long> H(N);
  if (N <= K) {
    cout << 0 << endl;
  } else {
    for (int i = 0; i < N; i++)
      cin >> H.at(i);
    for (int i = 0; i < K; i++) {
      for (int j = 0; j < N - i - 1; j++) {
        if (H.at(j) > H.at(j + 1)) {
          int a = H.at(j);
          H.at(j) = H.at(j + 1);
          H.at(j + 1) = a;
        };
      };
    };
    long ans = 0;
    for (int i = 0; i < N - K; i++)
      ans += H.at(i);
    cout << ans << endl;
  };
}

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

int main() {
  int n, k;
  long long ans;
  ans = 0;
  cin >> n >> k;
  vector<int> h(n);
  for (int i = 0; i < n; i++)
    cin >> h.at(i);
  sort(h.begin(), h.end());
  for (int i = 0; i < n - k; i++)
    ans += h.at(i);
  cout << ans << endl;
}
Problem p02785 (Python)

Buggy submission (status: Time Limit Exceeded):
class Solution:
    def solve(self, H, k, monsters):
        monsters.sort(reverse=True)

        i = 0

        while i < k and len(monsters) > 0:
            monsters.pop(0)
            i += 1

        ans = 0

        for monster in monsters:
            ans += monster

        return ans


sol = Solution()

[H, k] = list(map(int, input().strip().split()))
monsters = list(map(int, input().strip().split()))

print(sol.solve(H, k, monsters))


Fixed submission:
class Solution:
    def solve(self, H, k, monsters):
        monsters.sort(reverse=True)

        return sum(monsters[k:])


sol = Solution()

[H, k] = list(map(int, input().strip().split()))
monsters = list(map(int, input().strip().split()))

print(sol.solve(H, k, monsters))
Problem p02785 (Python)

Buggy submission (status: Time Limit Exceeded):
N, K = [int(_) for _ in input().split()]
H = [int(_) for _ in input().split()]
list_H = sorted(H, reverse=True)
if len(H) < K:
    print(0)
else:
    for k in range(K):
        if len(list_H) > 0:
            list_H.pop(0)
    print(sum(list_H))


Fixed submission:
N, K = [int(_) for _ in input().split()]
H = [int(_) for _ in input().split()]
H.sort(reverse=True)
print(sum(H[K:]))
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
using namespace std;
int main() {
  int n, k, h[100001];
  long long count = 0;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++)
    scanf("%d", &h[i]);
  sort(h, h + n);
  for (int i = n - 1 - k; i >= 0; i--) {
    count += h[i];
  }
  printf("%lld", count);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
using namespace std;
int main() {
  int n, k, h[200001];
  long long count = 0;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++)
    scanf("%d", &h[i]);
  sort(h, h + n);
  for (int i = n - 1 - k; i >= 0; i--) {
    count += h[i];
  }
  printf("%lld", count);
  return 0;
}
Problem p02785 (C++)

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

using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

const long long INF = 1LL << 60;
#define PI 3.14159265359
bool dp[100100];

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

  vector<int> H(N);
  rep(i, N) cin >> H[i];

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

  rep(i, K) H[i] = 0;
  long long ans = 0;
  rep(i, N) ans += H[i];

  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

const long long INF = 1LL << 60;
#define PI 3.14159265359
bool dp[100100];

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

  vector<int> H(N);
  rep(i, N) cin >> H[i];

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

  rep(i, min(N, K)) H[i] = 0;
  long long ans = 0;
  rep(i, N) ans += H[i];

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int cmp(int x, int y) { return x > y; }

int main() {
  int n, k;
  int a[100005];
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n, cmp);
  if (n <= k)
    cout << "0";
  else {
    long long s = 0;
    for (int i = k; i < n; i++)
      s += a[i];
    cout << s << endl;
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int cmp(int x, int y) { return x > y; }

int main() {
  int n, k;
  int a[200005];
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n, cmp);
  if (n <= k)
    cout << "0";
  else {
    long long s = 0;
    for (int i = k; i < n; i++)
      s += a[i];
    cout << s << endl;
  }
  return 0;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int k, n, i;
  long long int c = 0, h[100000];
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    cin >> h[i];
  }
  sort(h, h + n, greater<int>());
  for (i = k; i < n; i++) {
    c += h[i];
  }
  { cout << c << endl; }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int k, n, i;
  long long int c = 0, h[1000000];
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    cin >> h[i];
  }
  sort(h, h + n, greater<int>());
  for (i = k; i < n; i++) {
    c += h[i];
  }
  { cout << c << endl; }

  return 0;
}