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

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
#define fill(a) memset(a, 0, sizeof(a))
#define all(v) (v).begin(), (v).end()
#define sp(k) cout << setprecision(k) << fixed;
#define rep(i, a) for (int(i) = 0; (i) < (int)(a); (i)++)
#define rep1(i, a, b) for (int i = (a); i <= (b); ++i)
#define irep(i, b, a) for (int i = (b); i >= (a); --i)
#define minv(v) *min_element(v.begin(), v.end())
#define maxv(v) *max_element(v.begin(), v.end())
#define each(it, s) for (auto it = s.begin(); it != s.end(); ++it)
#define unq(v)                                                                 \
  sort(all(v)), (v).erase(unique((v).begin(), (v).end()), (v).end())
#define getpos(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define _ios                                                                   \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define endl "\n"
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int maxn = 2000100;

int main() {
  _ios;

  ll n, k;
  cin >> n >> k;
  vll h(n);
  rep(i, n) cin >> h[i];
  sort(all(h));
  reverse(all(h));
  int x = 0;
  while (k--) {
    h[x++] = 0;
  }
  int sum = 0;
  for (int i = 0; i < n; i++) {
    sum += h[i];
  }
  cout << sum << endl;

  return 0;
}


Fixed submission:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
#define fill(a) memset(a, 0, sizeof(a))
#define all(v) (v).begin(), (v).end()
#define sp(k) cout << setprecision(k) << fixed;
#define rep(i, a) for (int(i) = 0; (i) < (int)(a); (i)++)
#define rep1(i, a, b) for (int i = (a); i <= (b); ++i)
#define irep(i, b, a) for (int i = (b); i >= (a); --i)
#define minv(v) *min_element(v.begin(), v.end())
#define maxv(v) *max_element(v.begin(), v.end())
#define each(it, s) for (auto it = s.begin(); it != s.end(); ++it)
#define unq(v)                                                                 \
  sort(all(v)), (v).erase(unique((v).begin(), (v).end()), (v).end())
#define getpos(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define _ios                                                                   \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define endl "\n"
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int maxn = 2000100;

int main() {
  _ios;

  ll n, k;
  cin >> n >> k;
  vll h(n);
  rep(i, n) cin >> h[i];
  sort(all(h));
  n -= k;
  ll sum = 0;
  for (ll i = 0; i < n; i++) {
    sum += h[i];
  }
  cout << sum << endl;

  return 0;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
#include <ctype.h>
#include <float.h>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <string.h>
#include <string>
using namespace std;

int main() {

  int N, K, H[100000] = {};
  long long ans = 0;
  cin >> N >> K;

  if (K >= N) {
    cout << 0 << endl;
    return 0;
  }

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

  sort(H, H + N, greater<int>());

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

  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <ctype.h>
#include <float.h>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <string.h>
#include <string>
using namespace std;

int main() {

  int N, K, H[1000000];
  long long ans = 0;
  cin >> N >> K;

  if (K >= N) {
    cout << 0 << endl;
    return 0;
  }

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

  sort(H, H + N, greater<int>());

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

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

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

int main() {
  lli n, k, i;
  cin >> n >> k;

  lli a[n];
  lli sum = 0;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  if (k >= n) {
    cout << 0;
    return 0;
  } else {
    for (i = n - 1; i >= 0; i++) {
      if (k == 0)
        break;
      else
        sum -= a[i];
      k--;
    }
    cout << sum;
  }
}


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

int main() {
  lli n, k, i;
  cin >> n >> k;

  lli a[n];
  lli sum = 0;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  if (k >= n) {
    cout << 0;
    return 0;
  } else {
    sort(a, a + n);
    for (i = n - 1; i >= 0; i--) {
      if (k == 0)
        break;
      else
        sum -= a[i];
      k--;
    }
    cout << sum;
  }
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <time.h>
#include <vector>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64, i64> P;

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;
}

int n, k, a[101010];

int main() {
  cin >> n >> k;
  i64 ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  sort(a, a + n);

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

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <time.h>
#include <vector>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64, i64> P;

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;
}

int n, k, a[201010];

int main() {
  cin >> n >> k;
  i64 ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  sort(a, a + n);

  for (int i = 0; i < n - k; i++) {
    ans += a[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 PI 3.14159265358979323846
#define int long long
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int N, K;
  cin >> N >> K;

  int H[N];
  int sum = 0;
  rep(i, N) {
    cin >> H[i];
    sum += H[i];
  }
  sort(H, H + N);
  reverse(H, H + N);
  rep(i, K) { sum -= H[i]; }
  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 PI 3.14159265358979323846
#define int long long
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int N, K;
  cin >> N >> K;

  int H[N];
  int sum = 0;
  rep(i, N) {
    cin >> H[i];
    sum += H[i];
  }
  sort(H, H + N);
  reverse(H, H + N);
  rep(i, min(K, N)) { sum -= H[i]; }
  cout << sum << endl;
}
Problem p02785 (C++)

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define big ((ll)(1e9) + 7)

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


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define big ((ll)(1e9) + 7)

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> h;
  for (ll i = 0; i < n; i++) {
    ll H;
    cin >> H;
    h.push_back(H);
  }
  sort(h.rbegin(), h.rend());
  if (n > k) {
    for (ll i = 0; i < k; i++) {
      h[i] = 0;
    }
  } else {
    cout << 0 << endl;
    return 0;
  }
  ll sum = 0;
  for (ll i = 0; i < n; i++) {
    sum += h[i];
  }
  cout << sum << endl;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define big ((ll)(1e9) + 7)

// double c(double x)
// {
//   double X = x;
//   X = int(X) % 10;
//   return X;
// }

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


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define big ((ll)(1e9) + 7)

// double c(double x)
// {
//   double X = x;
//   X = int(X) % 10;
//   return X;
// }

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> h(n);
  for (ll i = 0; i < n; i++) {
    cin >> h[i];
  }
  sort(h.rbegin(), h.rend());
  for (ll i = 0; i < min(k, n); i++) {
    h[i] = 0;
  }
  ll sum = 0;
  for (ll i = 0; i < n; i++) {
    sum += h[i];
  }
  cout << sum << endl;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  // 体力の高いモンスターの順にソート
  // k番目の要素から体力を足し算して出力
  int N, K;
  cin >> N >> K;
  int h[10 ^ 6 + 10];
  for (int i = 0; i < N; ++i)
    cin >> h[i];
  sort(h, h + N, greater<int>());

  long sum = 0;
  for (int i = K; i < N; ++i)
    sum += h[i];
  cout << sum << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  // 体力の高いモンスターの順にソート
  // k番目の要素から体力を足し算して出力
  int N, K;
  cin >> N >> K;
  int h[200010];
  for (int i = 0; i < N; ++i)
    cin >> h[i];
  sort(h, h + N, greater<int>());

  long sum = 0;
  for (int i = K; i < N; ++i)
    sum += h[i];
  cout << sum << endl;
}
Problem p02785 (C++)

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

typedef long long int ll;
ll powk(ll a, ll n) {
  ll r = 1;
  for (ll i = 0; i < n; i++) {
    r *= a;
  }

  return r;
}

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> h(n);
  for (ll i = 0; i < n; i++) {
    cin >> h[i];
  }

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

  for (ll i = n - 1; i >= n - k; i--) {
    h[i] = 0;
  }

  ll ans = 0;
  for (ll i = 0; i < n; i++) {
    ans += h[i];
  }

  cout << ans;

  return 0;
}

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

typedef long long int ll;
ll powk(ll a, ll n) {
  ll r = 1;
  for (ll i = 0; i < n; i++) {
    r *= a;
  }

  return r;
}

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> h(n);
  for (ll i = 0; i < n; i++) {
    cin >> h[i];
  }

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

  for (ll i = n - 1; i >= n - k && i >= 0; i--) {
    h[i] = 0;
  }

  ll ans = 0;
  for (ll i = 0; i < n; i++) {
    ans += h[i];
  }

  cout << ans;

  return 0;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;
using LL = long long;

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

  vector<LL> H(N);

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

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

  cout << accumulate(H.begin() + K, H.end(), 0L) << endl;
}

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

using namespace std;
using LL = long long;

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

  vector<LL> H(N);

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

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

  LL ans = 0;

  if (H.size() > K)
    ans = accumulate(H.begin() + K, H.end(), 0L);

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

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

using u32 = uint32_t;
using u64 = uint64_t;
using i32 = int32_t;
using i64 = int64_t;

int main() {
  std::ios_base::sync_with_stdio(0);

  i64 n, k;

  std::cin >> n >> k;

  std::vector<i64> h(n);

  for (i64 i = 0; i < n; ++i) {
    std::cin >> h[i];
  }

  std::sort(h.begin(), h.end(), std::greater<i64>());

  for (i64 i = 0; i < k; ++i) {
    h[i] = 0;
  }

  i64 ans = std::accumulate(h.begin(), h.end(), 0LL);

  std::cout << ans << "\n";

  return 0;
}

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

using u32 = uint32_t;
using u64 = uint64_t;
using i32 = int32_t;
using i64 = int64_t;

int main() {
  std::ios_base::sync_with_stdio(0);

  i64 n, k;

  std::cin >> n >> k;

  std::vector<i64> h(n);

  for (i64 i = 0; i < n; ++i) {
    std::cin >> h[i];
  }

  std::sort(h.begin(), h.end(), std::greater<i64>());

  for (i64 i = 0; i < std::min(k, n); ++i) {
    h[i] = 0;
  }

  i64 ans = std::accumulate(h.begin(), h.end(), 0LL);

  std::cout << ans << "\n";

  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 lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  sort(h.begin(), h.end(), greater<>());
  h.erase(h.begin(), h.begin() + k);
  ll ans = 0;
  rep(i, h.size()) 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++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  sort(h.begin(), h.end(), greater<>());
  k = min(k, n);
  h.erase(h.begin(), h.begin() + k);
  ll ans = 0;
  rep(i, h.size()) 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++)
using namespace std;
using ll = long long;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  sort(h.begin(), h.end());
  rep(i, k) { h.pop_back(); }
  ll sum = 0;
  rep(i, h.size()) sum += h[i];
  cout << sum << 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;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  sort(h.begin(), h.end());
  k = min(n, k);
  rep(i, k) { h.pop_back(); }
  ll sum = 0;
  rep(i, h.size()) sum += h[i];
  cout << sum << endl;
  return 0;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
// list index out of rangeエラー表示用
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)

int main() {
  int n, k;
  cin >> n >> k;
  vector<long long> H(n);
  rep(i, 0, n) { cin >> H[i]; }
  rep(i, 0, n) {}
  sort(H.begin(), H.end());
  rep(i, 0, k) { H.pop_back(); }
  cout << accumulate(H.begin(), H.end(), 0LL);
}

Fixed submission:
// list index out of rangeエラー表示用
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)

int main() {
  int n, k;
  cin >> n >> k;
  vector<long long> H(n);
  rep(i, 0, n) { cin >> H[i]; }
  rep(i, 0, n) {}
  sort(H.begin(), H.end());
  rep(i, 0, k) {
    if (!H.empty())
      H.pop_back();
  }
  H.push_back(0);
  cout << accumulate(H.begin(), H.end(), 0LL);
}
Problem p02785 (C++)

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

Int N, M, K;
Int X, Y, Z, D;
const int MAXN = 105;
Int B, C;

struct DisJointSet {
  vector<int> SZ;
  vector<int> ID;
  int n;

  DisJointSet(int n) {
    SZ.resize(n);
    ID.resize(n);
    this->n = n;

    for (int i = 0; i < n; ++i) {
      ID[i] = i;
      SZ[i] = 1;
    }
  }

  int find(int x) { return (ID[x] == x ? x : find(ID[x])); }

  void Union_find(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y)
      return;
    if (SZ[x] > SZ[y]) {
      ID[y] = x;
      SZ[x] += SZ[y];
    } else {
      ID[x] = y;
      SZ[y] += SZ[x];
    }
    return;
  }
};

int main() {

  cin >> N >> M;
  vector<Int> A(N);
  Int sum = 0;
  for (auto &x : A)
    cin >> x, sum += x;
  sort(A.rbegin(), A.rend());
  Int ans = 0;

  for (int i = 0; i < M; ++i) {
    ans += A[i];
  }

  ans = sum - ans;
  ans = max(ans, 0LL);
  cout << ans << "\n";
}

Fixed submission:
#include <bits/stdc++.h>
#define Int long long
#define pb push_back
using namespace std;

Int N, M, K;
Int X, Y, Z, D;
const int MAXN = 105;
Int B, C;

struct DisJointSet {
  vector<int> SZ;
  vector<int> ID;
  int n;

  DisJointSet(int n) {
    SZ.resize(n);
    ID.resize(n);
    this->n = n;

    for (int i = 0; i < n; ++i) {
      ID[i] = i;
      SZ[i] = 1;
    }
  }

  int find(int x) { return (ID[x] == x ? x : find(ID[x])); }

  void Union_find(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y)
      return;
    if (SZ[x] > SZ[y]) {
      ID[y] = x;
      SZ[x] += SZ[y];
    } else {
      ID[x] = y;
      SZ[y] += SZ[x];
    }
    return;
  }
};

int main() {

  cin >> N >> M;
  vector<Int> A(N);
  Int sum = 0;
  for (auto &x : A)
    cin >> x, sum += x;
  sort(A.rbegin(), A.rend());
  Int ans = 0;

  for (int i = 0; i < min(N, M); ++i) {
    ans += A[i];
  }

  ans = sum - ans;
  ans = max(ans, 0LL);
  cout << ans << "\n";
}
Problem p02785 (C++)

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

#define ll long long
#define fornum(A, B, C) for (A = B; A < C; ++A)
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

/////////////////////////////////////////////////////
ll N, K, H[101010];
ll i, j, k;
int main() {
  scanf("%lld%lld", &N, &K);

  fornum(i, 0, N) { scanf("%lld", &H[i]); }
  sort(H, H + N);
  if (N <= K) {
    printf("0");
    return 0;
  }
  fornum(i, 0, K) { H[N - 1 - i] = 0; }
  ll ans = 0;
  fornum(i, 0, N) { ans += H[i]; }
  printf("%lld", ans);

  return 0;
}

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

#define ll long long
#define fornum(A, B, C) for (A = B; A < C; ++A)
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

/////////////////////////////////////////////////////
ll N, K, H[202020];
ll i, j, k;
int main() {
  scanf("%lld%lld", &N, &K);

  fornum(i, 0, N) { scanf("%lld", &H[i]); }
  sort(H, H + N);
  if (N <= K) {
    printf("0");
    return 0;
  }
  fornum(i, 0, K) { H[N - 1 - i] = 0; }
  ll ans = 0;
  fornum(i, 0, N) { ans += H[i]; }
  printf("%lld", ans);

  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;
using P = pair<int, int>;
using ll = long long;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i, n) cin >> h[i];

  sort(h.rbegin(), h.rend());
  rep(i, k) h[i] = 0;

  ll ans = 0;
  rep(i, n) ans += h[i];
  cout << ans << endl;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i, n) cin >> h[i];

  sort(h.rbegin(), h.rend());
  if (k > n)
    k = n;
  rep(i, k) h[i] = 0;

  ll ans = 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;
template <typename T> using vec = vector<T>;

int main() {
  int n, k;
  cin >> n >> k;
  vec<long> h(n);
  for (auto &&e : h) {
    cin >> e;
  }
  sort(h.rbegin(), h.rend());

  long ans = 0ll;
  auto it = h.begin();
  it += k;
  while (it != h.end()) {
    ans += *it;
    it++;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;

int main() {
  int n, k;
  cin >> n >> k;
  vec<long> h(n);
  for (auto &&e : h) {
    cin >> e;
  }
  sort(h.rbegin(), h.rend());

  long ans = 0ll;
  auto it = h.begin();
  while (it != h.end() and k != 0) {
    it++;
    k--;
  }
  while (it != h.end()) {
    ans += *it;
    it++;
  }
  cout << ans << endl;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mem(dp, v) memset(dp, v, sizeof dp);
using namespace std;

const int N = 1e3 + 7, inf = 1e9;
ll ar[N], dp[N][N], n, k, t;

int main() {
  ll n, k, pw = 1, tot = 0;
  // ios_base::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
  }
  sort(ar, ar + n);
  for (int i = n - k - 1; i >= 0; i--)
    tot += ar[i];
  cout << tot << "\n";
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mem(dp, v) memset(dp, v, sizeof dp);
using namespace std;

const int N = 1e6 + 7, inf = 1e9;
ll ar[N], n, k, t;

int main() {
  ll n, k, pw = 1, tot = 0;
  // ios_base::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
  }
  sort(ar, ar + n);
  for (int i = n - k - 1; i >= 0; i--)
    tot += ar[i];
  cout << tot << "\n";
  return 0;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  long long int n, k;
  long long int all[100006];
  long long int attackTimes = 0;
  cin >> n >> k;
  for (long long int i = 0; i < n; i++)
    cin >> all[i];
  sort(all, all + n);
  // cout<<all[0]<<endl;
  long long int t = n - k;
  if (k >= n) {
    cout << attackTimes << endl;
    return 0;
  } else {
    for (long long int i = 0; i < t; i++)
      attackTimes += all[i];
  }
  cout << attackTimes << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  long long int n, k;
  long long int all[300006];
  long long int attackTimes = 0;
  cin >> n >> k;
  for (long long int i = 0; i < n; i++)
    cin >> all[i];
  sort(all, all + n);
  // cout<<all[0]<<endl;
  long long int t = n - k;
  if (k >= n) {
    cout << attackTimes << endl;
    return 0;
  } else {
    for (long long int i = 0; i < t; i++)
      attackTimes += all[i];
  }
  cout << attackTimes << endl;
  return 0;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long int ll;

#define MOD 998244353

ll gcd(ll a, ll b) {
  if (a % b == 0)
    return (b);
  else
    return (gcd(b, a % b));
}

bool primeNumber(ll n) {
  if (n < 2)
    return false;
  else {
    for (ll i = 2; i * i <= n; i++) {
      if (n % i == 0)
        return false;
    }
    return true;
  }
}

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

  for (ll i = 0; i < n; i++) {
    cin >> h[i];
  }
  sort(h.begin(), h.end(), greater<ll>());

  ll total = 0;
  for (ll i = 0; i < n; i++) {
    total += h[i];
  }

  for (ll i = 0; i < k; i++) {
    total -= h[i];
  }

  cout << total << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long int ll;

#define MOD 998244353

ll gcd(ll a, ll b) {
  if (a % b == 0)
    return (b);
  else
    return (gcd(b, a % b));
}

bool primeNumber(ll n) {
  if (n < 2)
    return false;
  else {
    for (ll i = 2; i * i <= n; i++) {
      if (n % i == 0)
        return false;
    }
    return true;
  }
}

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

  for (ll i = 0; i < n; i++) {
    cin >> h[i];
  }
  sort(h.begin(), h.end(), greater<ll>());

  ll total = 0;
  for (ll i = 0; i < n; i++) {
    total += h[i];
  }

  for (ll i = 0; i < min(k, n); i++) {
    total -= h[i];
  }

  cout << total << endl;
  return 0;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n); i++)
#define dunk(n) cout << n << endl
#define all(a) (a).begin(), (a).end()
typedef pair<int, int> P;
typedef long long ll;

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> hp(n);
  rep(i, n) cin >> hp[i];
  sort(all(hp));
  reverse(all(hp));
  ll ans = 0;
  for (int i = k - 1; i < n; i++) {
    ans += hp[i];
  }
  dunk(ans);
  return 0;
}

Fixed submission:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n); i++)
#define dunk(n) cout << n << endl
#define all(a) (a).begin(), (a).end()
typedef pair<int, int> P;
typedef long long ll;

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> hp(n);
  rep(i, n) cin >> hp[i];
  sort(all(hp));
  reverse(all(hp));
  ll ans = 0;
  for (int i = k; i < n; i++) {
    ans += hp[i];
  }
  dunk(ans);
  return 0;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ld long double
#define pii pair<int, int>
#define sz(a) (int)(a.size())
#define resize(v) v.resize(unique(all(v)) - v.begin());
#define all(a) a.begin(), a.end()
#define forit(it, s)                                                           \
  for (__typeof(s.begin()) it = s.begin(); it != s.end(); it++)

// random_device rd; mt19937 g(rd());

using namespace std;
using namespace __gnu_pbds;

void Fast_Read_Out() {
  ios_base::sync_with_stdio(0);
  cin.tie(), cout.tie();
}

void Random() {
  unsigned int seed;
  asm("rdtsc" : "=A"(seed));
  srand(seed);
}

unsigned int Time() {
  unsigned int time = clock() / 1000.00;
  return time;
}

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int mod = (int)1e9 + 7;
const int N = (int)1e5 + 123;

int a[N];

int main() {
#ifdef JUDGE
  freopen("input.txt", "r", stdin);
#endif
  Fast_Read_Out();
  Random();
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  sort(a + 1, a + n + 1);
  reverse(a + 1, a + n + 1);
  long long sum = 0;
  for (int i = k + 1; i <= n; i++)
    sum += a[i];
  cout << sum;
}

Fixed submission:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ld long double
#define pii pair<int, int>
#define sz(a) (int)(a.size())
#define resize(v) v.resize(unique(all(v)) - v.begin());
#define all(a) a.begin(), a.end()
#define forit(it, s)                                                           \
  for (__typeof(s.begin()) it = s.begin(); it != s.end(); it++)

// random_device rd; mt19937 g(rd());

using namespace std;
using namespace __gnu_pbds;

void Fast_Read_Out() {
  ios_base::sync_with_stdio(0);
  cin.tie(), cout.tie();
}

void Random() {
  unsigned int seed;
  asm("rdtsc" : "=A"(seed));
  srand(seed);
}

unsigned int Time() {
  unsigned int time = clock() / 1000.00;
  return time;
}

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int mod = (int)1e9 + 7;
const int N = (int)2e5 + 123;

int a[N];

int main() {
#ifdef JUDGE
  freopen("input.txt", "r", stdin);
#endif
  Fast_Read_Out();
  Random();
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  sort(a + 1, a + n + 1);
  reverse(a + 1, a + n + 1);
  long long sum = 0;
  for (int i = k + 1; i <= n; i++)
    sum += a[i];
  cout << sum;
}
Problem p02785 (C++)

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

int main() {
  int64_t N, K;
  vector<int64_t> H(100010);

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

  sort(H.begin(), H.begin() + N);

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

  cout << ans << endl;
}


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

int main() {
  int64_t N, K;
  vector<int64_t> H(200010);

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

  sort(H.begin(), H.begin() + N);

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

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define INCANT                                                                 \
  cin.tie(0), cout.tie(0), ios::sync_with_stdio(false),                        \
      cout << fixed << setprecision(20);
#define int long long
#define gcd __gcd
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, T b) { return (a = max(a, b)) == b; }
template <class T> bool chmin(T &a, T b) { return (a = min(a, b)) == b; }
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for (int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for (auto &&i : n)
const int INF = 1e18, MOD = 1e9 + 7;
signed main() {
  INCANT;
  int n, k, h, res = 0;
  cin >> n >> k;
  priority_queue<int> q;
  rep(i, n) {
    cin >> h;
    q.push(h);
  }
  while (k--) {
    q.pop();
  }
  while (!q.empty()) {
    res += q.top();
    q.pop();
  }
  cout << res << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define INCANT                                                                 \
  cin.tie(0), cout.tie(0), ios::sync_with_stdio(false),                        \
      cout << fixed << setprecision(20);
#define int long long
#define gcd __gcd
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, T b) { return (a = max(a, b)) == b; }
template <class T> bool chmin(T &a, T b) { return (a = min(a, b)) == b; }
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for (int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for (auto &&i : n)
const int INF = 1e18, MOD = 1e9 + 7;
signed main() {
  INCANT;
  int n, k, h, res = 0;
  cin >> n >> k;
  priority_queue<int> q;
  rep(i, n) {
    cin >> h;
    q.push(h);
  }
  while (k-- && !q.empty()) {
    q.pop();
  }
  while (!q.empty()) {
    res += q.top();
    q.pop();
  }
  cout << res << endl;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

#define LL long long
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1

const int maxn = 1e5 + 7;

int a[maxn];

int main() {
  int n, k;
  while (~scanf("%d%d", &n, &k)) {
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
    }
    sort(a + 1, a + n + 1);
    LL sum = 0;
    for (int i = 1; i <= n - k; i++) {
      sum += 1LL * a[i];
    }
    printf("%lld\n", sum);
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

#define LL long long
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1

const int maxn = 2e5 + 7;

int a[maxn];

int main() {
  int n, k;
  while (~scanf("%d%d", &n, &k)) {
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
    }
    sort(a + 1, a + n + 1);
    LL sum = 0;
    for (int i = 1; i <= n - k; i++) {
      sum += 1LL * a[i];
    }
    printf("%lld\n", sum);
  }
  return 0;
}
Problem p02785 (C++)

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

int main(int argc, char const *argv[]) {

  ll n, k;
  ll h[20000];

  cin >> n;
  cin >> k;
  rep(i, n) { cin >> h[i]; }

  sort(h, h + n, greater<ll>());

  ll dmg = 0;
  for (int i = k; i < n; i++) {
    dmg += h[i];
  }
  cout << dmg;

  return 0;
}


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

int main(int argc, char const *argv[]) {

  ll n, k;
  ll h[1000000];

  cin >> n;
  cin >> k;
  rep(i, n) { cin >> h[i]; }

  sort(h, h + n, greater<ll>());

  ll dmg = 0;
  for (int i = k; i < n; i++) {
    dmg += h[i];
  }
  cout << dmg;

  return 0;
}
Problem p02785 (C++)

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

int main() {
  long long int h, n, dif, sum = 0, a[1000];
  cin >> h >> n;
  dif = h - n;
  if (dif <= 0)
    cout << "0" << endl;
  else {
    for (long long int i = 0; i < h; i++) {
      cin >> a[i];
      // sum += a;
    }
    sort(a, a + h);
    for (int i = 0; i < h - n; i++) {
      sum += a[i];
    }
    cout << sum << endl;
  }
  return 0;
}

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

int main() {
  long long int h, n, dif, sum = 0, a[1000000];
  cin >> h >> n;
  dif = h - n;
  if (dif <= 0)
    cout << "0" << endl;
  else {
    for (long long int i = 0; i < h; i++) {
      cin >> a[i];
      // sum += a;
    }
    sort(a, a + h);
    for (int i = 0; i < h - n; i++) {
      sum += a[i];
    }
    cout << sum << endl;
  }
  return 0;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
ll w[100000];
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, k, sum = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    w[i] = a;
  }
  sort(w, w + n);
  for (int i = 0; i < n - k; i++)
    sum += w[i];
  cout << sum << '\n';
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
ll w[300000];
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, k, sum = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    w[i] = a;
  }
  sort(w, w + n);
  for (int i = 0; i < n - k; i++)
    sum += w[i];
  cout << sum << '\n';
  return 0;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <stdio.h>

int main(void) {
  long long N, K, H[200005], S, i;
  scanf("%lld%lld", &N, &K);
  for (i = 0; i < N; i++)
    scanf("%lld", &H[i]);
  std::sort(H, H + N);
  for (i = N - K; i < N; i++)
    H[i] = 0;
  S = 0;
  for (i = 0; i < N; i++)
    S += H[i];
  printf("%lld", S);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <stdio.h>

int main(void) {
  long long N, K, H[200005], S, i;
  scanf("%lld%lld", &N, &K);
  if (K >= N) {
    printf("0");
    return 0;
  }
  for (i = 0; i < N; i++)
    scanf("%lld", &H[i]);
  std::sort(H, H + N);
  for (i = N - K; i < N; i++)
    H[i] = 0;
  S = 0;
  for (i = 0; i < N; i++)
    S += H[i];
  printf("%lld", S);
  return 0;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll int n, k, i, ar[100005], ans;
int main() {

  cin >> n >> k;
  for (i = 0; i < n; i++)
    cin >> ar[i];
  sort(ar, ar + n);
  for (i = 0; i < n - k; i++)
    ans += ar[i];
  cout << ans;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll int n, k, i, ar[200005], ans;
int main() {

  cin >> n >> k;
  for (i = 0; i < n; i++)
    cin >> ar[i];
  sort(ar, ar + n);
  for (i = 0; i < n - k; i++)
    ans += ar[i];
  cout << ans;
  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++)

int main() {
  int n, k;
  cin >> n >> k;
  vector<long> hn(n);
  rep(i, n) { cin >> hn[i]; }
  sort(hn.begin(), hn.end());
  reverse(hn.begin(), hn.end());
  long sum = 0;
  rep(i, k) { hn[i] = 0; }
  rep(i, n) { sum += hn[i]; }
  cout << sum;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  if (n <= k) {
    cout << 0;
    return 0;
  }
  vector<long> hn(n);
  rep(i, n) { cin >> hn[i]; }
  sort(hn.begin(), hn.end());
  reverse(hn.begin(), hn.end());
  long sum = 0;
  rep(i, k) { hn[i] = 0; }
  rep(i, n) { sum += hn[i]; }
  cout << sum;
}
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;

void merge_sort(int array[], int left, int right) {
  int i, j, k, mid;
  int work[10];
  if (left < right) {
    mid = (left + right) / 2;
    merge_sort(array, left, mid);
    merge_sort(array, mid + 1, right);
    for (i = mid; i >= left; i--)
      work[i] = array[i];
    for (j = mid + 1; j <= right; j++)
      work[right - (j - (mid + 1))] = array[j];
    i = left;
    j = right;
    for (k = left; k <= right; k++) {
      if (work[i] < work[j]) {
        array[k] = work[i++];
      } else {
        array[k] = work[j--];
      }
    }
  }
}

int main(void) {
  int n, k;
  int h[200010];
  int i;
  ll ans = 0;

  cin >> n >> k;

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

  merge_sort(h, 0, n - 1);

  for (i = 0; i < n - k; i++) {
    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;

void merge_sort(int array[], int left, int right) {
  int i, j, k, mid;
  int work[200010];
  if (left < right) {
    mid = (left + right) / 2;
    merge_sort(array, left, mid);
    merge_sort(array, mid + 1, right);
    for (i = mid; i >= left; i--)
      work[i] = array[i];
    for (j = mid + 1; j <= right; j++)
      work[right - (j - (mid + 1))] = array[j];
    i = left;
    j = right;
    for (k = left; k <= right; k++) {
      if (work[i] < work[j]) {
        array[k] = work[i++];
      } else {
        array[k] = work[j--];
      }
    }
  }
}

int main(void) {
  int n, k;
  int h[200010];
  int i;
  ll ans = 0;

  cin >> n >> k;

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

  merge_sort(h, 0, n - 1);

  for (i = 0; i < n - k; i++) {
    ans += h[i];
  }

  cout << ans << endl;

  return 0;
}
Problem p02785 (C++)

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

int main() {

  int N, K;
  int H[20010];
  cin >> N >> K;
  for (int i = 0; i < N; i++)
    cin >> H[i];
  if (N <= K)
    cout << 0 << endl;
  else {
    sort(H, H + N);
    long ans = 0;
    for (int i = 0; i < (N - K); i++)
      ans += H[i];
    cout << ans << endl;
  }

  return 0;
}

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

int main() {

  int N, K;
  int H[200010];
  cin >> N >> K;
  for (int i = 0; i < N; i++)
    cin >> H[i];
  if (N <= K)
    cout << 0 << endl;
  else {
    sort(H, H + N);
    long ans = 0;
    for (int i = 0; i < (N - K); i++)
      ans += H[i];
    cout << ans << endl;
  }

  return 0;
}
Problem p02785 (C++)

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

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

  int n, k;
  cin >> n >> k;

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

  sort(h, h + n, greater<ll>());
  for (int i = 0; i < k; ++i)
    h[i] = 0;

  cout << accumulate(h, h + n, 0LL) << '\n';

  return (0);
}


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

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

  int n, k;
  cin >> n >> k;

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

  sort(h, h + n, greater<ll>());
  for (int i = 0; i < min(k, n); ++i)
    h[i] = 0;

  cout << accumulate(h, h + n, 0LL) << '\n';

  return (0);
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
// inlclude前用define
#define _USE_MATH_DEFINES

// include
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <type_traits>
#include <vector>
// #include<deque>
#include <iomanip>
#include <limits>
#include <map>
#include <set>
#include <tuple>

using namespace std;

// typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

// define
#define INF 1e9
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> h(n);
  rep(i, n) { cin >> h[i]; }
  sort(all(h));
  reverse(all(h));
  ll ans = 0;
  for (int i = 0; i < k; i++) {
    h[i] = 0;
  }
  rep(i, n) { ans += h[i]; }
  cout << ans << endl;
}


Fixed submission:
// inlclude前用define
#define _USE_MATH_DEFINES

// include
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <type_traits>
#include <vector>
// #include<deque>
#include <iomanip>
#include <limits>
#include <map>
#include <set>
#include <tuple>

using namespace std;

// typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

// define
#define INF 1e9
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> h(n);
  rep(i, n) { cin >> h[i]; }
  sort(all(h));
  reverse(all(h));
  ll ans = 0;
  if (k > n)
    k = n;
  for (int i = 0; i < k; i++) {
    h[i] = 0;
  }
  rep(i, n) { ans += h[i]; }
  cout << ans << endl;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define MOD7 1000000007
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> H(N);
  for (int i = 0; i < N; i++)
    cin >> H[i];
  sort(all(H));
  reverse(all(H));
  for (int i = 0; i < K; i++) {
    if (i > N)
      break;
    H[i] = 0;
  }
  ll sum = 0;
  for (int h : H)
    sum += h;
  cout << sum << endl;
}


Fixed submission:
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define MOD7 1000000007
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> H(N);
  for (int i = 0; i < N; i++)
    cin >> H[i];
  sort(all(H));
  reverse(all(H));
  for (int i = 0; i < K; i++) {
    if (i >= N)
      break;
    H[i] = 0;
  }
  ll sum = 0;
  for (int h : H)
    sum += h;
  cout << sum << endl;
}
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; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> data(n);
  REP(i, n) cin >> data[i];
  ll sum = 0;
  sort(ALL(data), greater<int>());
  REP(i, k) { data[i] = 0; }
  REP(i, n) { sum += data[i]; }
  cout << sum << 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; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> data(n);
  REP(i, n) cin >> data[i];
  ll sum = 0;
  sort(ALL(data), greater<int>());
  REP(i, min(k, n)) { data[i] = 0; }
  REP(i, n) { sum += data[i]; }
  cout << sum << endl;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int K;
  cin >> K;
  vector<long long int> H;
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  sort(H.begin(), H.end());
  reverse(H.begin(), H.end());
  long long int ans = 0;
  for (int i = K; i < N; i++) {
    ans = ans + H[i];
  }
  cout << ans;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int K;
  cin >> K;
  vector<long long int> H(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  sort(H.begin(), H.end());
  reverse(H.begin(), H.end());
  long long int ans = 0;
  for (int i = K; i < N; i++) {
    ans = ans + H[i];
  }
  cout << ans;
  return 0;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<long> h;
  for (int i = 0; i < n; ++i) {
    long t;
    cin >> t;
    h.push_back(t);
  }
  sort(h.begin(), h.end(), greater<long>());
  for (int i = 0; i < k; ++i) {
    h[i] = 0;
  }
  cout << accumulate(h.begin(), h.end(), 0L) << endl;
  return 0;
}

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

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<long> h;
  for (int i = 0; i < n; ++i) {
    long t;
    cin >> t;
    h.push_back(t);
  }
  sort(h.begin(), h.end(), greater<long>());
  for (int i = 0; i < min(k, n); ++i) {
    h[i] = 0;
  }
  cout << accumulate(h.begin(), h.end(), 0L) << endl;
  return 0;
}