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

Buggy submission (status: Runtime Error):
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define vi vector<int>
#define br cout << "\n";
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define tr(c, i) for (auto i : c)
#define pii pair<int, int>
#define fast_io()                                                              \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(nullptr)
#define pq                                                                     \
  priority_queue<pair<ll, pii>, vector<pair<ll, pii>>, greater<pair<ll, pii>>> \
      p; // container adapter makes ascending q
#define er(x) cout << x << " "
#define err(x, y) cout << x << " " << y
using namespace std;

const ll MAX = 1000 * 1000;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
const int MOD = 1000 * 1000 * 1000 + 7;
const int N = 301;
const int INF = INT_MAX;
const int M = 200005;
int main() {

  ll n, k;
  cin >> n >> k;
  std::vector<ll> h;
  for (auto &x : h)
    cin >> x;

  sort(rall(h));
  ll sum = 0;
  for (int i = k; i < n; ++i)
    sum += h[i];

  cout << sum;
  return 0;
}


Fixed submission:
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define vi vector<int>
#define br cout << "\n";
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define tr(c, i) for (auto i : c)
#define pii pair<int, int>
#define fast_io()                                                              \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(nullptr)
#define pq                                                                     \
  priority_queue<pair<ll, pii>, vector<pair<ll, pii>>, greater<pair<ll, pii>>> \
      p; // container adapter makes ascending q
#define er(x) cout << x << " "
#define err(x, y) cout << x << " " << y
using namespace std;

const ll MAX = 1000 * 1000;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
const int MOD = 1000 * 1000 * 1000 + 7;
const int N = 301;
const int INF = INT_MAX;
const int M = 200005;
int main() {

  ll n, k;
  cin >> n >> k;
  std::vector<ll> h(n);
  for (auto &x : h)
    cin >> x;

  sort(rall(h));
  ll sum = 0;
  for (int i = k; i < n; ++i)
    sum += h[i];

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

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

int main() {
  // your code goes here
  long long int n, k;
  cin >> n >> k;
  long long int arr[n], sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr + n);
  reverse(arr, arr + n);
  for (int j = 0; j < k; j++) {
    arr[j] = 0;
  }
  for (int i = 0; i < n; i++) {
    sum = sum + arr[i];
  }
  cout << sum;

  return 0;
}

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

int main() {
  // your code goes here
  long long int n, k;
  cin >> n >> k;
  long long int arr[n], sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr + n);
  reverse(arr, arr + n);
  for (int j = 0; j < k; j++) {
    if (j < n)
      arr[j] = 0;
  }
  for (int i = 0; i < n; i++) {
    sum = sum + arr[i];
  }
  cout << sum;

  return 0;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int Max = 1000000;
int main() {
  int N, K;
  cin >> N >> K;

  ll H[N];

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

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

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

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int Max = 1000000;
int main() {
  int N, K;
  cin >> N >> K;

  ll H[N];

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

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

  ll 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>
#define ll long long
using namespace std;
int a[30000];
bool cmp(int x, int y) { return x > y; }
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n, cmp);
  ll sum = 0;
  for (int i = k; i < n; i++)
    sum += a[i];
  cout << sum << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int a[300000];
bool cmp(int x, int y) { return x > y; }
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n, cmp);
  ll sum = 0;
  for (int i = k; i < n; i++)
    sum += a[i];
  cout << sum << endl;
}
Problem p02785 (C++)

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

using namespace std;

typedef long long ll;
typedef pair<ll, int> P;

int main() {
  int n, k;
  ll h[100000];

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

  sort(h, h + n);
  reverse(h, h + n);

  for (int i = 0; i < k; i++)
    h[i] = 0;

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

  cout << sum << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <istream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, int> P;

int main() {
  int n, k;
  ll h[200000];

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

  sort(h, h + n);
  reverse(h, h + n);

  for (int i = 0; i < k; i++)
    h[i] = 0;

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

  cout << sum << endl;

  return 0;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <iostream>
#define LL long long
using namespace std;

int n, t;
int p;
LL ans;
int a[100002];

inline int qr() {
  int w = 1, x = 0;
  char a = 0;
  while (a < '0' || a > '9') {
    if (a == '-')
      w = -1;
    a = getchar();
  }
  while (a >= '0' && a <= '9') {
    x = (x << 3) + (x << 1) + (a ^ 48);
    a = getchar();
  }
  return x * w;
}

bool mycmp(int a, int b) { return a > b; }

int main() {
  n = qr();
  t = qr();
  for (int i = 1; i <= n; i++)
    a[i] = qr();
  sort(a + 1, a + n + 1, mycmp);
  if (t >= n)
    cout << "0" << endl;
  else {
    for (int i = t + 1; i <= n; i++)
      ans += a[i];
    cout << ans << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
#define LL long long
using namespace std;

int n, t;
int p;
LL ans;
int a[900002];

inline int qr() {
  int w = 1, x = 0;
  char a = 0;
  while (a < '0' || a > '9') {
    if (a == '-')
      w = -1;
    a = getchar();
  }
  while (a >= '0' && a <= '9') {
    x = (x << 3) + (x << 1) + (a ^ 48);
    a = getchar();
  }
  return x * w;
}

bool mycmp(int a, int b) { return a > b; }

int main() {
  n = qr();
  t = qr();
  for (int i = 1; i <= n; i++)
    a[i] = qr();
  sort(a + 1, a + n + 1, mycmp);
  if (t >= n)
    cout << "0" << endl;
  else {
    for (int i = t + 1; i <= n; i++)
      ans += a[i];
    cout << ans << endl;
  }
  return 0;
}
Problem p02785 (C++)

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

using namespace std;

int n, m, a[100005], mx;
long long cnt;

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

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

using namespace std;

int n, m, a[1000005], mx;
long long cnt;

int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  if (n - m <= 0) {
    cout << 0;
    return 0;
  }
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n - m; i++) {
    cnt += a[i];
  }
  cout << cnt;
  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;
  int h[n];

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

  sort(h, h + n);

  long long d = accumulate(h, h + n - k, 0LL);
  cout << d << "\n";

  return 0;
}

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

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  int h[n];

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

  sort(h, h + n);

  n = max(0, n - k);

  long long d = accumulate(h, h + n, 0LL);
  cout << d << "\n";

  return 0;
}
Problem p02785 (C++)

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

#define all(x) (x).begin(), (x).end()
#define puts(x) cout << x << endl;
#define rep(i, m, n) for (int i = m; i < n; i++)
#define fore(i, a) for (auto i : a)
#define ll long long
using namespace std;
ll n, k;
ll h[100005];
int main() {
  cin >> n >> k;
  rep(i, 0, n) { cin >> h[i]; }
  sort(h, h + n); // 昇順
  ll ans = 0;
  rep(i, 0, n - k) { ans += h[i]; }
  puts(ans);
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <string>

#define all(x) (x).begin(), (x).end()
#define puts(x) cout << x << endl;
#define rep(i, m, n) for (int i = m; i < n; i++)
#define fore(i, a) for (auto i : a)
#define ll long long
using namespace std;
ll n, k;
ll h[1000005];
int main() {
  cin >> n >> k;
  rep(i, 0, n) { cin >> h[i]; }
  sort(h, h + n); // 昇順
  ll ans = 0;
  rep(i, 0, n - k) { ans += h[i]; }
  puts(ans);
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <deque>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<long long> monsters(n);
  unsigned long long total = 0;
  for (int i = 0; i < n; i++) {
    cin >> monsters[i];
    total += monsters[i];
  }
  sort(monsters.begin(), monsters.end());
  if (k == 0)
    cout << total << endl;
  else if (k >= n) {
    cout << 0 << endl;
  } else {
    for (int i = n - 1; i >= 0; i++) {
      total -= monsters[i];
      k--;
      if (k == 0)
        break;
    }
    cout << total << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <deque>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<long long> monsters(n);
  unsigned long long total = 0;
  for (int i = 0; i < n; i++) {
    cin >> monsters[i];
    total += monsters[i];
  }
  sort(monsters.begin(), monsters.end());
  if (k == 0)
    cout << total << endl;
  else if (k >= n) {
    cout << 0 << endl;
  } else {
    for (int i = n - 1; i >= 0; i--) {
      total -= monsters[i];
      k--;
      if (k == 0)
        break;
    }
    cout << total << endl;
  }
  return 0;
}
Problem p02785 (C++)

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

using namespace std;

long long n, k, mons[100005], ans;

int main() {
  cin >> n >> k;
  if (k >= n) {
    cout << 0;
    return 0;
  }
  for (int i = 0; i < n; i++)
    cin >> mons[i];
  sort(mons, mons + n);
  for (int i = 0; i < n - k; i++)
    ans += mons[i];
  cout << ans << endl;
  return 0;
}

Fixed submission:
#pragma GCC optimize(2)
#include <bits/stdc++.h>

using namespace std;

long long n, k, mons[200005], ans;

int main() {
  cin >> n >> k;
  if (k >= n) {
    cout << 0;
    return 0;
  }
  for (int i = 0; i < n; i++)
    cin >> mons[i];
  sort(mons, mons + n);
  for (int i = 0; i < n - k; i++)
    ans += mons[i];
  cout << ans << endl;
  return 0;
}
Problem p02785 (C++)

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

typedef long long ll;
typedef unsigned long long ull;

const int N = 1e5 + 20;

ll a[N];

int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  ll n, k, sum = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  if (k >= n)
    return cout << 0 << endl, 0;
  sort(a, a + n);
  for (int i = 0; i < n - k; i++)
    sum += a[i];
  cout << sum << endl;
  return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;

const int N = 2e5 + 20;

ll a[N];

int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  ll n, k, sum = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  if (k >= n)
    return cout << 0 << endl, 0;
  sort(a, a + n);
  for (int i = 0; i < n - k; i++)
    sum += a[i];
  cout << sum << endl;
  return 0;
}
Problem p02785 (C++)

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

using namespace std;

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

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

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

using namespace std;

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<long long> h(n);
  long long ans = 0;
  if (k >= n) {
    cout << 0 << endl;
    return 0;
  }
  rep(i, 0, n) {
    cin >> h[i];
    ans += h[i];
  }
  sort(h.begin(), h.end());
  for (int i = n - 1; i > n - k - 1; --i) {
    ans -= h[i];
  }
  cout << ans << endl;
}
Problem p02785 (C++)

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

using namespace std;
using ll = long long;
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  sort(h.rbegin(), h.rend());
  for (int i = 0; i < k; i++) {
    h[i] = 0;
  }
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ans += h[i];
  }
  cout << ans << endl;
}

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

using namespace std;
using ll = long long;
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  sort(h.rbegin(), h.rend());
  for (int i = 0; i < k; i++) {
    if (i >= n) {
      break;
    }
    h[i] = 0;
  }
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ans += h[i];
  }
  cout << ans << endl;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define all(v) (v).begin(), (v).end()
#define pb push_back

ll power(ll a, ll b) { // a^b
  ll res = 1;
  while (b > 0) {
    if (b & 1) {
      res = (res * a);
      b--;
    }
    a = (a * a);
    b >>= 1;
  }
  return res;
}

ll gcd(ll a, ll b) { return (b == 0) ? a : gcd(b, a % b); }

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, k;
  cin >> n >> k;
  vl h(n);
  ll sum = 0;
  for (ll i = 0; i < n; i++) {
    cin >> h[i];
    sum += h[i];
  }
  sort(all(h));
  for (ll i = n - 1; i >= 0; i++) {
    if (k == 0)
      break;
    sum -= h[i];
    k--;
  }
  cout << sum << "\n";
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define all(v) (v).begin(), (v).end()
#define pb push_back

ll power(ll a, ll b) { // a^b
  ll res = 1;
  while (b > 0) {
    if (b & 1) {
      res = (res * a);
      b--;
    }
    a = (a * a);
    b >>= 1;
  }
  return res;
}

ll gcd(ll a, ll b) { return (b == 0) ? a : gcd(b, a % b); }

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, k;
  cin >> n >> k;
  vl h(n);
  ll sum = 0;
  for (ll i = 0; i < n; i++) {
    cin >> h[i];
    sum += h[i];
  }
  sort(all(h));
  for (ll i = n - 1; i >= 0; i--) {
    if (k == 0)
      break;
    sum -= h[i];
    k--;
  }
  cout << sum << "\n";
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  sort(all(h));
  reverse(all(h));
  rep(i, k) h[i] = 0;
  ll ans = 0;
  rep(i, n) ans += h[i];
  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  if (k > n) {
    cout << 0 << endl;
    return 0;
  }
  sort(all(h));
  reverse(all(h));
  rep(i, k) h[i] = 0;
  ll ans = 0;
  rep(i, n) ans += h[i];
  cout << ans << endl;

  return 0;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
// #pragma GCC optimize("O2147483647")
// #pragma GCC optimize("inline")
// #pragma GCC optimize("-ffast-math")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("inline-small-functions")
// #pragma GCC optimize("-finline-small-functions")
// #pragma GCC optimize("-fexpensive-optimizations")
// #pragma GCC optimize("-funsafe-loop-optimizations")
// #pragma GCC optimize("inline-functions-called-once")
// #pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx,avx")
// #pragma GCC optimze("fast-math")
// #define GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include "testlib.h"
#define rep(i, j, k) for (int i = (int)(j); i < (int)(k); i++)
#define per(i, j, k) for (int i = (int)(k); i >= (int)(j); i--)
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)((x).size())
#define fprd fprintf(stderr,
#define fi first
#define se second
#define endl '\n'
using namespace std;
typedef long long ll;
// #define int ll
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pi> vpi;

const int N = 1e5 + 5;
int n, k, a[N];
ll sum = 0;

int main() {
  scanf("%d%d", &n, &k);
  rep(i, 0, n) scanf("%d", &a[i]);
  sort(a, a + n);
  rep(i, 0, n - k) sum += a[i];
  printf("%lld\n", sum);
}

Fixed submission:
// #pragma GCC optimize("O2147483647")
// #pragma GCC optimize("inline")
// #pragma GCC optimize("-ffast-math")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("inline-small-functions")
// #pragma GCC optimize("-finline-small-functions")
// #pragma GCC optimize("-fexpensive-optimizations")
// #pragma GCC optimize("-funsafe-loop-optimizations")
// #pragma GCC optimize("inline-functions-called-once")
// #pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx,avx")
// #pragma GCC optimze("fast-math")
// #define GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include "testlib.h"
#define rep(i, j, k) for (int i = (int)(j); i < (int)(k); i++)
#define per(i, j, k) for (int i = (int)(k); i >= (int)(j); i--)
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)((x).size())
#define fprd fprintf(stderr,
#define fi first
#define se second
#define endl '\n'
using namespace std;
typedef long long ll;
// #define int ll
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pi> vpi;

const int N = 2e5 + 5;
int n, k, a[N];
ll sum = 0;

int main() {
  scanf("%d%d", &n, &k);
  rep(i, 0, n) scanf("%d", &a[i]);
  sort(a, a + n);
  rep(i, 0, n - k) sum += a[i];
  printf("%lld\n", sum);
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define elif else if
#define INF 1000000007
using namespace std;
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int n, m, cnt = 0, aa[110000], k;
pair<int, int> p[110000];
string s;
char c;
signed main() {
  cin >> n >> k;
  rep(i, n) { cin >> aa[i]; }
  sort(aa, aa + n);
  rep(i, n - k) { cnt += aa[i]; }
  cout << cnt;
}

Fixed submission:
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define elif else if
#define INF 1000000007
using namespace std;
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int n, m, cnt = 0, aa[220000], k;
pair<int, int> p[110000];
string s;
char c;
signed main() {
  cin >> n >> k;
  rep(i, n) { cin >> aa[i]; }
  sort(aa, aa + n);
  rep(i, n - k) { cnt += aa[i]; }
  cout << cnt;
}
Problem p02785 (C++)

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

const int N = (1e5) + 5;
int n, a[N];
int k;

int main() { // claudio van
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  if (k < n) {
    sort(a, a + n);
    ll sum = 0;
    for (int i = 0; i < n - k; ++i) {
      sum += a[i];
    }
    cout << sum << "\n";
  } else {
    cout << 0 << "\n";
  }
  return 0;
}

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

const int N = (2e5) + 5;
int n, a[N];
int k;

int main() { // claudio van
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  if (k < n) {
    sort(a, a + n);
    ll sum = 0;
    for (int i = 0; i < n - k; ++i) {
      sum += a[i];
    }
    cout << sum << "\n";
  } else {
    cout << 0 << "\n";
  }
  return 0;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define mp make_pair
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(c) c.begin(), c.end()
#define pb push_back
#define fi first
#define se second
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
int n, k;
int h[100005];
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++)
    scanf("%d", &h[i]);
  sort(h, h + n);
  ll sum = 0;
  for (int i = 0; i < n - k; i++)
    sum += h[i];
  printf("%lld\n", sum);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define mp make_pair
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(c) c.begin(), c.end()
#define pb push_back
#define fi first
#define se second
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
int n, k;
int h[200005];
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++)
    scanf("%d", &h[i]);
  sort(h, h + n);
  ll sum = 0;
  for (int i = 0; i < n - k; i++)
    sum += h[i];
  printf("%lld\n", sum);
  return 0;
}
Problem p02785 (C++)

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

int main() {
  ll result = 0;

  ll N = 1, K = 0;
  cin >> N >> K;

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

  sort(H.begin(), H.end(), greater<ll>());
  for (ll i = 0; i < K; i++) {
    result -= H[i];
  }

  cout << result << endl;
  return 0;
}


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

int main() {
  ll result = 0;

  ll N = 1, K = 0;
  cin >> N >> K;

  vector<ll> H(max(N, K), 0);
  for (ll i = 0; i < N; i++) {
    cin >> H[i];
    result += H[i];
  }

  sort(H.begin(), H.end(), greater<ll>());
  for (ll i = 0; i < K; i++) {
    result -= H[i];
  }

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define N 20005
#define ll long long
ll a[N];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++)
    scanf("%lld", &a[i]);
  if (k >= n)
    printf("0");
  else {
    ll ans = 0;
    int c = n - k;
    sort(a + 1, a + 1 + n);
    for (int i = 1; i <= c; i++)
      ans += a[i];
    printf("%lld", ans);
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define N 200005
#define ll long long
ll a[N];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++)
    scanf("%lld", &a[i]);
  if (k >= n)
    printf("0");
  else {
    ll ans = 0;
    int c = n - k;
    sort(a + 1, a + 1 + n);
    for (int i = 1; i <= c; i++)
      ans += a[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++)
#define all(v) v.begin(), v.end()
#define len(x) (ll)(x).length()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int a, int b) {
  if (a % b == 0) {
    return b;
  } else {
    return (gcd(b, a % b));
  }
}
ll lcm(int a, int b) { return a * b / gcd(a, b); }
const int INF = 1e9;
const ll INFS = 1e18;
const int MOD = INF + 7;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const double PI = acos(-1);

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  sort(all(h));
  reverse(all(h));
  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++)
#define all(v) v.begin(), v.end()
#define len(x) (ll)(x).length()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int a, int b) {
  if (a % b == 0) {
    return b;
  } else {
    return (gcd(b, a % b));
  }
}
ll lcm(int a, int b) { return a * b / gcd(a, b); }
const int INF = 1e9;
const ll INFS = 1e18;
const int MOD = INF + 7;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const double PI = acos(-1);

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  sort(all(h));
  reverse(all(h));
  if (n <= k) {
    cout << 0 << endl;
    return 0;
  }
  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>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

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

  sort(h.begin(), h.end(), greater<ll>());

  rep(i, k) h[i] = 0;
  ll sumH = 0;
  rep(i, n) { sumH += h[i]; }
  cout << sumH << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n, k;
  cin >> n >> k;
  vl h(n);
  rep(i, n) cin >> h[i];
  if (n <= k) {
    cout << 0 << endl;
    return 0;
  }
  sort(h.begin(), h.end(), greater<ll>());

  rep(i, k) h[i] = 0;
  ll sumH = 0;
  rep(i, n) { sumH += h[i]; }
  cout << sumH << endl;
  return 0;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using VL = vector<ll>;

#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++)
const long long INF = 999999999;

ll h[100010];

int main() {
  ll n, k, ans = 0;
  cin >> n >> k;
  REP(i, n) cin >> h[i];
  sort(h, h + n);
  REPR(i, n - k - 1) { ans += h[i]; }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using VL = vector<ll>;

#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++)
const long long INF = 999999999;

ll h[200010];

int main() {
  ll n, k, ans = 0;
  cin >> n >> k;
  REP(i, n) cin >> h[i];
  sort(h, h + n);
  REPR(i, n - k - 1) { ans += h[i]; }
  cout << ans << endl;
}
Problem p02785 (Python)

Buggy submission (status: Time Limit Exceeded):
N, K = map(int, input().split())
list_H = [int(x) for x in input().split()]

list_H.sort()

while K:
    if list_H:
        list_H.pop()
    K -= 1

sum = 0
while list_H:
    sum += list_H[0]
    list_H.pop(0)

print(sum)


Fixed submission:
N, K = map(int, input().split())
list_H = [int(x) for x in input().split()]

list_H.sort()

while K:
    if list_H:
        list_H.pop()
    K -= 1

print(sum(list_H))
Problem p02785 (Python)

Buggy submission (status: Time Limit Exceeded):
import sys
from io import StringIO
import unittest


def resolve():
    N, K = [int(i) for i in input().split()]
    H = [int(i) for i in input().split()]
    for i in range(K):
        if len(H) > 0:
            idx = H.index(max(H))
            H[idx] = 0
        else:
            break
    sumH = 0
    if len(H) > 0:
        sumH = sum(H)
    print(sumH)


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3 1
4 1 5"""
        output = """5"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """8 9
7 9 3 2 3 8 4 6"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """3 0
1000000000 1000000000 1000000000"""
        output = """3000000000"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()


Fixed submission:
import sys
from io import StringIO
import unittest


def resolve():
    N, K = [int(i) for i in input().split()]
    H = sorted([int(i) for i in input().split()])
    if N <= K:
        H = [0]
    else:
        # if K < (N - K):
        for i in range(K):
            H[len(H) - 1 - i] = 0
        # else:
        #     Hs = []
        #     for i in range(N - K):
        #         Hs.append(H[i])
        #     H = Hs
    print(sum(H))


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3 1
4 1 5"""
        output = """5"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """8 9
7 9 3 2 3 8 4 6"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """3 0
1000000000 1000000000 1000000000"""
        output = """3000000000"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
using namespace std;
#define int long long
const int MAXN = 100005;
int n, k;
int a[MAXN];

signed main()

{
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> a[i];

  if (n <= k) {
    cout << 0 << endl;
    return 0;
  }

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

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

  cout << sum << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
#define int long long
const int MAXN = 200005;
int n, k;
int a[MAXN];

signed main()

{
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> a[i];

  if (n <= k) {
    cout << 0 << endl;
    return 0;
  }

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

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

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <iostream>
// #include <algorithm>
//  #include <iomanip>
#define ll long long

using namespace std;

const int MOD = 1000000007;

int main() {
  ll n, k;
  scanf("%lld %lld", &n, &k);

  vector<ll> h(n);
  for (ll i = 0; i < n; i++) {
    scanf("%lld", &h[i]);
  }
  sort(h.begin(), h.end());

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

  cout << sum << endl;
}

// 3 1
// 4 1 5


Fixed submission:
#include <bits/stdc++.h>
#include <iostream>
// #include <algorithm>
//  #include <iomanip>
#define ll long long

using namespace std;

const int MOD = 1000000007;

int main() {
  ll n, k;
  scanf("%lld %lld", &n, &k);

  vector<ll> h(n);
  for (ll i = 0; i < n; i++) {
    scanf("%lld", &h[i]);
  }
  sort(h.begin(), h.end());

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

  cout << sum << endl;
}

// 3 1
// 4 1 5
Problem p02785 (C++)

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

using namespace std;

using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main() {
  ll n, m, i, j, k;
  cin >> n >> k;
  vector<ll> A(n);
  for (auto &x : A)
    cin >> x;
  sort(A.rbegin(), A.rend());
  for (i = 0; i < k; i++) {
    A[i] = 0;
  }
  ll ret = 0;
  for (i = 0; i < n; i++) {
    ret += A[i];
  }
  cout << ret << endl;
  return 0;
}

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

using namespace std;

using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main() {
  ll n, m, i, j, k;
  cin >> n >> k;
  vector<ll> A(n);
  for (auto &x : A)
    cin >> x;
  sort(A.rbegin(), A.rend());
  for (i = 0; i < min(n, k); i++) {
    A[i] = 0;
  }
  ll ret = 0;
  for (i = 0; i < n; i++) {
    ret += A[i];
  }
  cout << ret << endl;
  return 0;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
int a[maxn];
bool cmp(int a, int b) { return a > b; }
int main(void) {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n, cmp);
  if (k >= n) {
    cout << 0 << endl;
  } else {
    ll sum = 0;
    for (int i = k; i < n; i++) {
      sum += a[i];
    }
    cout << sum << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 10;
int a[maxn];
bool cmp(int a, int b) { return a > b; }
int main(void) {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n, cmp);
  if (k >= n) {
    cout << 0 << endl;
  } else {
    ll sum = 0;
    for (int i = k; i < n; i++) {
      sum += a[i];
    }
    cout << sum << endl;
  }
  return 0;
}
Problem p02785 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const ll MAX_N = 100000;

int main() {
  ll n, k;
  ll sum = 0;
  ll t;
  std::vector<int> H;
  scanf("%lld%lld", &n, &k);
  rep(i, n) {
    scanf("%lld", &t);
    H.push_back(t);
  }
  sort(H.begin(), H.end());

  rep(i, n - k) {
    // printf("%lld",H.front());
    sum += H.front();
    H.erase(H.begin());
  }
  printf("%lld", sum);

  return 0;
}

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

int main() {
  ll n, k;
  ll sum = 0;
  ll t;
  std::vector<int> H;
  scanf("%lld%lld", &n, &k);
  rep(i, n) {
    scanf("%lld", &t);
    H.push_back(t);
  }
  sort(H.begin(), H.end());

  rep(i, n - k) {
    // printf("%lld",H.front());
    sum += H[i];
    // H.erase(H.begin());
  }
  printf("%lld", sum);

  return 0;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, m, n) for (int i = m; i <= n; i++)
#define sd(n) scanf("%d", &n)
#define sl(n) scanf("%lld", &n)
#define met(a, b)                                                              \
  ;                                                                            \
  memset(a, b, sizeof(a));
typedef long long ll;
using namespace std;
double pai = 3.141592653589793;

inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}

// inline long long read() {
//     long long tmp=0, fh=1; char c=getchar();
//     while (c<'0'||c>'9') {if (c=='-') fh=-1; c=getchar();}
//     while (c>='0'&&c<='9') tmp=tmp*10+c-48, c=getchar();
//     return tmp*fh;
// }
ll h[200005];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    scanf("%lld", h[i]);
  }
  sort(h, h + n);
  ll ans = 0;
  for (int i = 0; i < n - k; i++) {
    ans += h[i];
  }
  cout << ans;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, m, n) for (int i = m; i <= n; i++)
#define sd(n) scanf("%d", &n)
#define sl(n) scanf("%lld", &n)
#define met(a, b)                                                              \
  ;                                                                            \
  memset(a, b, sizeof(a));
typedef long long ll;
using namespace std;
double pai = 3.141592653589793;

inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}

// inline long long read() {
//     long long tmp=0, fh=1; char c=getchar();
//     while (c<'0'||c>'9') {if (c=='-') fh=-1; c=getchar();}
//     while (c>='0'&&c<='9') tmp=tmp*10+c-48, c=getchar();
//     return tmp*fh;
// }
ll h[200005];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    scanf("%lld", &h[i]);
  }
  sort(h, h + n);
  ll ans = 0;
  for (int i = 0; i < n - k; i++) {
    ans += h[i];
  }
  cout << ans;
}
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;
const ll mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()

template <class T> inline void chmin(T &a, T b) {
  if (a > b) {
    a = b;
  }
}

template <class T> inline void chmax(T &a, T b) {
  if (a < b) {
    a = b;
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(10);
  ll N, K;
  cin >> N >> K;
  vector<ll> H(N);
  REP(i, N) cin >> H[i];
  sort(all(H), greater<ll>());
  REP(i, K) H[i] = 0;
  ll answer = 0;
  REP(i, N) answer += H[i];
  cout << answer << "\n";
}

Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()

template <class T> inline void chmin(T &a, T b) {
  if (a > b) {
    a = b;
  }
}

template <class T> inline void chmax(T &a, T b) {
  if (a < b) {
    a = b;
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(10);
  ll N, K;
  cin >> N >> K;
  vector<ll> H(N);
  REP(i, N) cin >> H[i];
  sort(all(H), greater<ll>());
  REP(i, K) {
    if (i == N)
      break;
    H[i] = 0;
  }
  ll answer = 0;
  REP(i, N) answer += H[i];
  cout << answer << "\n";
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
#define ull unsigned long long

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

  sort(A, A + N);
  ull sum = 0;
  for (ull i = 0; i < N - K; ++i) {
    sum += A[i];
  }
  cout << sum << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
#define ull signed long long

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

  sort(A, A + N);
  ull sum = 0;
  for (ull i = 0; i < N - K; ++i) {
    sum += A[i];
  }
  cout << sum << endl;
  return 0;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int N, K, C;
ll A[100001];
int B[100001];
vector<int> ans;

int main() {
  cin >> N >> K;
  ll sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A, A + N);
  for (int i = 0; i < N - K; i++) {
    sum += A[i];
  }
  cout << sum << endl;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int N, K, C;
ll A[200001];
int B[200001];
vector<int> ans;

int main() {
  cin >> N >> K;
  ll sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A, A + N);
  for (int i = 0; i < N - K; i++) {
    sum += A[i];
  }
  cout << sum << endl;
}
Problem p02785 (C++)

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

int main() {
  long long int h, a, s = 0, b, l, k;
  cin >> h >> a;

  long long int arr[a];

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

  sort(arr, arr + h);

  if (a >= h)
    cout << 0 << endl;

  else {
    l = h - a;
    s = 0;
    k = 0;
    for (int i = 0; i < l; i++) {
      s += arr[i];
    }

    cout << s << endl;
  }
}


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

int main() {
  long long int h, a, s = 0, b, l, k;
  cin >> h >> a;

  long long int arr[h];

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

  sort(arr, arr + h);

  if (a >= h)
    cout << 0 << endl;

  else {
    l = h - a;
    s = 0;
    k = 0;
    for (int i = 0; i < l; i++) {
      s += arr[i];
    }

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
using namespace std;
#define ll long long
/* run this program using the console pauser or add your own getch,
 * system("pause") or input loop */
ll a[100005];

int main(int argc, char **argv) {
  int h, n;
  scanf("%d%d", &n, &h);
  int sum = 0;
  for (int i = 1; i <= n; i++)
    scanf("%lld", &a[i]);
  sort(a + 1, a + n + 1);
  ll ans = 0;
  for (int i = n - h; i >= 1; i--) {
    ans += a[i];
  }
  cout << ans;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
#define ll long long
/* run this program using the console pauser or add your own getch,
 * system("pause") or input loop */
ll a[200005];

int main(int argc, char **argv) {
  int h, n;
  scanf("%d%d", &n, &h);
  int sum = 0;
  for (int i = 1; i <= n; i++)
    scanf("%lld", &a[i]);
  sort(a + 1, a + n + 1);
  ll ans = 0;
  for (int i = n - h; i >= 1; i--) {
    ans += a[i];
  }
  cout << 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++)
#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 PI 3.141592653589793
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

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; i++) {
    H[i] = 0;
  }

  ll atk = 0;
  for (ll i = 0; i < N; i++) {
    atk += H[i];
  }

  cout << atk << 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 PI 3.141592653589793
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
  ll N, K;
  cin >> N >> K;
  if (K > N) {
    cout << 0 << endl;
    return 0;
  }
  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; i++) {
    H[i] = 0;
  }

  ll atk = 0;
  for (ll i = 0; i < N; i++) {
    atk += H[i];
  }

  cout << atk << endl;
}