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

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<long> H(N);
  for (int i = 0; i < N; i++)
    cin >> H.at(i);
  long ans = 0;
  if (N <= K)
    cout << ans << endl;
  else {
    sort(H.begin(), H.end());
    sort(H.begin(), H.end(), greater<int>());
    //        reverse(H.begin(), H.end());
    for (int i = 0; i < K; i++)
      H.erase(H.begin());
    for (int i = 0; i < H.size(); i++)
      ans += H.at(i);
    cout << ans << endl;
  }
}


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

int main() {
  int N, K;
  cin >> N >> K;
  vector<long> H(N);
  for (int i = 0; i < N; i++)
    cin >> H.at(i);
  long ans = 0;
  if (N <= K)
    cout << ans << endl;
  else {
    sort(H.begin(), H.end());
    //        sort(H.begin(),H.end(),greater<int>());
    ////        reverse(H.begin(), H.end());
    //        for(int i=0;i<K;i++) H.erase(H.begin());
    for (int i = 0; i < N - K; i++)
      ans += H.at(i);
    cout << ans << endl;
  }
}
Problem p02785 (C++)

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

using namespace std;
long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}

long long gcd(long long a, long long b) {
  if (a < b)
    return gcd(b, a);
  long long r;
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  return b;
}

int main() {
  long long N, K, sum = 0;
  cin >> N >> K;
  vector<long long> H(N);
  for (size_t i = 0; i < N; i++) {
    cin >> H.at(i);
  }
  sort(H.begin(), H.end(), greater<int>());
  for (size_t i = 0; i < K; i++) {
    H.at(i) = 0;
  }
  for (size_t i = 0; i < N; i++) {
    sum += H.at(i);
  }
  cout << sum;
}


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

using namespace std;
long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}

long long gcd(long long a, long long b) {
  if (a < b)
    return gcd(b, a);
  long long r;
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  return b;
}

int main() {
  long long N, K, sum = 0;
  cin >> N >> K;
  vector<long long> H(N);
  for (size_t i = 0; i < N; i++) {
    cin >> H.at(i);
  }
  sort(H.begin(), H.end(), greater<int>());
  for (size_t i = 0; i < min(K, N); i++) {
    H.at(i) = 0;
  }
  for (size_t i = 0; i < N; i++) {
    sum += H.at(i);
  }
  cout << sum;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define MEM 100001
#define sanic ios_base::sync_with_stdio(0)
using namespace std;
const long long MOD = 1e9 + 9;
long long a, b, t;
long long p[MEM];
int main() {
  cin >> a >> b;
  for (int i = 1; i <= a; i++)
    cin >> p[i];
  sort(p + 1, p + a + 1, greater<int>());
  for (int i = b + 1; i <= a; i++)
    t += p[i];
  cout << t;
}


Fixed submission:
#include <bits/stdc++.h>
#define MEM 400001
#define sanic ios_base::sync_with_stdio(0)
using namespace std;
const long long MOD = 1e9 + 9;
long long a, b, t;
long long p[MEM];
int main() {
  cin >> a >> b;
  for (int i = 1; i <= a; i++)
    cin >> p[i];
  sort(p + 1, p + a + 1, greater<int>());
  for (int i = b + 1; i <= a; i++)
    t += p[i];
  cout << t;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <vector>
#define inf 1000000000
#define mod 1073741824
#pragma GCC optimization("O3")
using namespace std;
const int N = 100 * 1000 + 5;
#define all(x) begin(x), end(x)
int main() {

  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  // ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  long long int n, a, b, c = 0, m = 1e18;
  cin >> n >> a;
  vector<long long int> v(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  for (int i = 0; i < a; ++i) {
    v[i] = 0;
  }
  for (int i = 0; i < n; ++i) {
    if (v[i] != 0) {
      c += v[i];
    }
  }
  cout << c << "\n";
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <vector>
#define inf 1000000000
#define mod 1073741824
#pragma GCC optimization("O3")
using namespace std;
const int N = 100 * 1000 + 5;
#define all(x) begin(x), end(x)
int main() {

  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  // ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  long long int n, a, b, c = 0, m = 1e18;
  cin >> n >> a;
  vector<long long int> v(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  for (int i = a; i < n; ++i) {
    c += v[i];
  }
  cout << c << "\n";
  return 0;
}
Problem p02785 (C++)

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

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

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

  rep(i, K) { H[i] = 0; }

  ll ans = 0;

  rep(i, N) { ans += H[i]; }

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


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

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

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

  rep(i, min(K, N)) { 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):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for (int i = 0, i##_max = (N); i < i##_max; ++i)
#define repp(i, l, r) for (int i = (l), i##_max = (r); i < i##_max; ++i)
#define per(i, N) for (int i = (N)-1; i >= 0; --i)
#define perr(i, l, r) for (int i = r - 1, i##_min(l); i >= i##_min; --i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP                                                                \
  cin.tie(0);                                                                  \
  ios::sync_with_stdio(false);
#define MAX_I INT_MAX      // 1e9
#define MIN_I INT_MIN      //-1e9
#define MAX_UI UINT_MAX    // 1e9
#define MAX_LL LLONG_MAX   // 1e18
#define MIN_LL LLONG_MIN   //-1e18
#define MAX_ULL ULLONG_MAX // 1e19
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<char, char> PCC;
typedef pair<ll, ll> PLL;
typedef pair<char, int> PCI;
typedef pair<int, char> PIC;
typedef pair<ll, int> PLI;
typedef pair<int, ll> PIL;
typedef pair<ll, char> PLC;
typedef pair<char, ll> PCL;

inline void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
inline void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
inline void Yay(bool b) { cout << (b ? "Yay!" : ":(") << endl; }

int main(void) {
  SPEEDUP
  cout << setprecision(15);
  int N, K;
  cin >> N >> K;
  vector<int> H(N);
  rep(i, N) cin >> H[i];
  sort(all(H), greater<int>());
  rep(i, K) H[i] = 0;
  ll sum = 0;
  rep(i, N) sum += (ll)H[i];
  cout << sum << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for (int i = 0, i##_max = (N); i < i##_max; ++i)
#define repp(i, l, r) for (int i = (l), i##_max = (r); i < i##_max; ++i)
#define per(i, N) for (int i = (N)-1; i >= 0; --i)
#define perr(i, l, r) for (int i = r - 1, i##_min(l); i >= i##_min; --i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP                                                                \
  cin.tie(0);                                                                  \
  ios::sync_with_stdio(false);
#define MAX_I INT_MAX      // 1e9
#define MIN_I INT_MIN      //-1e9
#define MAX_UI UINT_MAX    // 1e9
#define MAX_LL LLONG_MAX   // 1e18
#define MIN_LL LLONG_MIN   //-1e18
#define MAX_ULL ULLONG_MAX // 1e19
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<char, char> PCC;
typedef pair<ll, ll> PLL;
typedef pair<char, int> PCI;
typedef pair<int, char> PIC;
typedef pair<ll, int> PLI;
typedef pair<int, ll> PIL;
typedef pair<ll, char> PLC;
typedef pair<char, ll> PCL;

inline void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
inline void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
inline void Yay(bool b) { cout << (b ? "Yay!" : ":(") << endl; }

int main(void) {
  SPEEDUP
  cout << setprecision(15);
  int N, K;
  cin >> N >> K;
  vector<int> H(N);
  rep(i, N) cin >> H[i];
  sort(all(H), greater<int>());
  rep(i, min(K, N)) H[i] = 0;
  ll sum = 0;
  rep(i, N) sum += (ll)H[i];
  cout << sum << endl;
  return 0;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
const int N = 1e5 + 7;
int h[N];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; ++i)
    scanf("%d", &h[i]);

  sort(h, h + n, greater<int>());
  long long res = 0;
  for (int i = k; i < n; ++i)
    res += h[i];
  cout << res;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
const int N = 2e5 + 7;
int h[N];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; ++i)
    scanf("%d", &h[i]);

  sort(h, h + n, greater<int>());
  long long res = 0;
  for (int i = k; i < n; ++i)
    res += h[i];
  cout << res;
  return 0;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ldb = long double;
using pa = pair<ll, ll>;
using vec = vector<ll>;

#define pb push_back
#define F first
#define S second
#define int ll
#define f(i, x, n) for (ll i = x; i < n; i++)
#define all(c) c.begin(), c.end()
#define edl "\n"
#define ceils(s, n) (s + n - 1) / n
#define str string
#define add insert
#define fast()                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL)

const int MOD = 1e9 + 7, N = 5e5 + 10;
const ll LINF = LLONG_MAX;

int32_t main() {
  fast();
  int n, k;
  cin >> n >> k;
  vec q(n);
  f(i, 0, n) { cin >> q[i]; }
  sort(all(q));
  reverse(all(q));
  f(i, 0, k) { q[i] = 0; }
  int c = 0;
  f(i, k, n) { c += q[i]; }
  cout << c;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ldb = long double;
using pa = pair<ll, ll>;
using vec = vector<ll>;

#define pb push_back
#define F first
#define S second
#define int ll
#define f(i, x, n) for (ll i = x; i < n; i++)
#define all(c) c.begin(), c.end()
#define edl "\n"
#define ceils(s, n) (s + n - 1) / n
#define str string
#define add insert
#define fast()                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL)

const int MOD = 1e9 + 7, N = 5e5 + 10;
const ll LINF = LLONG_MAX;

int32_t main() {
  fast();
  int n, k;
  cin >> n >> k;
  vec q(n);
  f(i, 0, n) { cin >> q[i]; }
  sort(all(q));
  reverse(all(q));
  if (k >= n) {
    cout << 0;
    return 0;
  }
  f(i, 0, k) { q[i] = 0; }
  int c = 0;
  f(i, k, n) { c += q[i]; }
  cout << c;

  return 0;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long int
#define endl "\n"
using namespace std;
void solve() {
  // Enter your code here Tanmay:)
  int n, k;
  cin >> n >> k;
  int arr[k];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr + n);
  int sum = 0;
  for (int i = n - k - 1; i >= 0; i--) {
    sum += arr[i];
  }
  cout << sum;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}
/*
int eulortotent(int n)
     {
    //Enter your code here Tanmay:)
    int total=n;
        for(int p=2;p*p<=n;p++)
        {
            if (n%p==0)
        {
            total /= p;
            total *= (p-1);
            while ( n % p == 0 )
                n /= p;
        }
    }

    if(n>1)
    {
        total/=n;
        total*=(n-1);
    }

  return total;
}
*/

Fixed submission:
#include <bits/stdc++.h>
#define int long long int
#define endl "\n"
using namespace std;
void solve() {
  // Enter your code here Tanmay:)
  int n, k;
  cin >> n >> k;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr + n);
  int sum = 0;
  for (int i = n - k - 1; i >= 0; i--) {
    sum += arr[i];
  }
  cout << sum;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}
/*
int eulortotent(int n)
     {
    //Enter your code here Tanmay:)
    int total=n;
        for(int p=2;p*p<=n;p++)
        {
            if (n%p==0)
        {
            total /= p;
            total *= (p-1);
            while ( n % p == 0 )
                n /= p;
        }
    }

    if(n>1)
    {
        total/=n;
        total*=(n-1);
    }

  return total;
}
*/
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define INF 1e9
#define all(v) v.begin(), v.end()
#define rall(v) v.begin(), v.end(), std::greater<int>()
#define rep(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define max(v) *max_element(v.begin(), v.end())
#define min(v) *min_element(v.begin(), v.end())
using namespace std;

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

  int n, k, t;
  cin >> n >> k;
  vector<int> h;
  rep(i, n) {
    cin >> t;
    h.pb(t);
  }
  sort(all(h));
  for (int i = 0; i < k; i++) {
    h[n - 1 - i] = 0;
  }
  long long sum = 0;
  rep(i, n) { sum += h[i]; }
  cout << sum << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define INF 1e9
#define all(v) v.begin(), v.end()
#define rall(v) v.begin(), v.end(), std::greater<int>()
#define rep(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define max(v) *max_element(v.begin(), v.end())
#define min(v) *min_element(v.begin(), v.end())
using namespace std;

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

  int n, k, t;
  cin >> n >> k;
  vector<int> h;
  rep(i, n) {
    cin >> t;
    h.pb(t);
  }
  sort(all(h));
  for (int i = 0; i < k; i++) {
    if (i > n) {
      break;
    }
    h[n - 1 - i] = 0;
  }
  long long sum = 0;
  rep(i, n) { sum += h[i]; }
  cout << sum << endl;
  return 0;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
long long temp[1000], a[100000], n, m, ans;
inline void __merge(int l, int r) {
  if (l == r)
    return;
  int mid = (l + r) >> 1;
  __merge(l, mid);
  __merge(mid + 1, r);
  int i = l, j = mid + 1;
  for (int k = l; k <= r; k++) {
    if ((i <= mid && a[i] < a[j]) || j > r)
      temp[k] = a[i++];
    else
      temp[k] = a[j++];
  }
  for (int k = l; k <= r; k++)
    a[k] = temp[k];
}
int main() {
  scanf("%lld%lld", &n, &m);
  if (m >= n) {
    puts("0");
    return 0;
  }
  for (int i = 1; i <= n; i++)
    scanf("%lld", &a[i]);
  __merge(1, n);

  for (int i = 1; i <= n - m; i++)
    ans += a[i];
  printf("%lld", ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
long long temp[200020], a[200020], n, m, ans;
inline void __merge(int l, int r) {
  if (l == r)
    return;
  int mid = (l + r) >> 1;
  __merge(l, mid);
  __merge(mid + 1, r);
  int i = l, j = mid + 1;
  for (int k = l; k <= r; k++) {
    if ((i <= mid && a[i] < a[j]) || j > r)
      temp[k] = a[i++];
    else
      temp[k] = a[j++];
  }
  for (int k = l; k <= r; k++)
    a[k] = temp[k];
}
int main() {
  scanf("%lld%lld", &n, &m);
  if (m >= n) {
    puts("0");
    return 0;
  }
  for (int i = 1; i <= n; i++)
    scanf("%lld", &a[i]);
  __merge(1, n);

  for (int i = 1; i <= n - m; i++)
    ans += a[i];
  printf("%lld", ans);
  return 0;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n, p[100005], k, ans = 0;
signed main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> p[i];
  sort(p, p + n);
  for (int i = 0; i < n - k; i++) {
    ans += p[i];
  }
  cout << ans;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n, p[200005], k, ans = 0;
signed main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> p[i];
  sort(p, p + n);
  for (int i = 0; i < n - k; i++) {
    ans += p[i];
  }
  cout << ans;
  return 0;
}
Problem p02785 (C++)

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> H(N);
  for (int i = 0; i < N; i++)
    cin >> H.at(i);

  sort(H.rbegin(), H.rend());

  for (int i = 0; i < K; i++)
    H.at(i) = 0;

  cout << accumulate(H.begin(), H.end(), 0L) << "\n";
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> H(N);
  for (int i = 0; i < N; i++)
    cin >> H.at(i);

  sort(H.rbegin(), H.rend());

  for (int i = 0; i < min(K, N); i++)
    H.at(i) = 0;

  cout << accumulate(H.begin(), H.end(), 0L) << "\n";
}
Problem p02785 (C++)

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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

long long INF = LLONG_MAX;

ll a[100111];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  // freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
  ll n, k;
  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 <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

long long INF = LLONG_MAX;

ll a[200222];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  // freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
  ll n, k;
  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;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

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

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  sort(h.rbegin(), h.rend());
  ll ans = 0;
  if (n <= k) {
    ans = 0;
  } else {
    for (int i = n - 1; i >= 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 int
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll i, j, k, n, m;
  cin >> n >> m;
  ll a[m];
  ll sum = 0;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  for (i = 0; i < (n - m); i++)
    sum += a[i];
  cout << sum;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll i, j, k, n, m;
  cin >> n >> m;
  ll a[n];
  ll sum = 0;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  for (i = 0; i < (n - m); i++)
    sum += a[i];
  cout << sum;
}
Problem p02785 (C++)

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> H(N);
  for (int i = 0; i < N; i++)
    cin >> H.at(i);
  sort(H.rbegin(), H.rend());
  cout << accumulate(H.begin() + K, H.end(), 0L) << "\n";
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> H(N);
  for (int i = 0; i < N; i++)
    cin >> H.at(i);
  sort(H.rbegin(), H.rend());
  K = min(N, K);
  cout << accumulate(H.begin() + K, H.end(), 0L) << "\n";
}
Problem p02785 (Python)

Buggy submission (status: Time Limit Exceeded):
import numpy as np

N, K = [int(i) for i in input().split()]
H = [int(h) for h in input().split()]

H = np.sort(np.array(H))[::-1]
for i in range(min(K, H.shape[0])):
    H = np.delete(H, 0)

print(np.sum(H))


Fixed submission:
import numpy as np

N, K = [int(i) for i in input().split()]
H = [int(h) for h in input().split()]

H = np.sort(np.array(H))[::-1]
H = H[min(K, H.shape[0]) :]

print(np.sum(H))
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define fast                                                                   \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
typedef long long ll;
ll strtoint(string str);
int main() {
  fast;
  ll n, k, cnt = 0;
  cin >> n >> k;
  vector<ll> arr(n);
  for (auto i = 0; i < n; ++i)
    cin >> arr[i];
  sort(arr.begin(), arr.end(), greater<>());
  for (auto i = 0; k; ++i) {
    arr[i] = 0;
    --k;
  }
  for (auto i = 0; i < n; ++i)
    cnt += arr[i];
  cout << cnt << '\n';
  return 0;
}
ll strtoint(string str) {
  ll x = 0;
  stringstream ss;
  ss << str;
  ss >> x;
  return x;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define fast                                                                   \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
typedef long long ll;
ll strtoint(string str);
int main() {
  fast;
  ll n, k, cnt = 0;
  cin >> n >> k;
  vector<ll> arr(n);
  for (auto i = 0; i < n; ++i)
    cin >> arr[i];
  sort(arr.begin(), arr.end(), greater<>());
  for (auto i = 0; k && i < n; ++i) {
    arr[i] = 0;
    --k;
  }
  for (auto i = 0; i < n; ++i)
    cnt += arr[i];
  cout << cnt << '\n';
  return 0;
}
ll strtoint(string str) {
  ll x = 0;
  stringstream ss;
  ss << str;
  ss >> x;
  return x;
}
Problem p02785 (C++)

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

using namespace std;

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, a, b) for (int i = int(a); i < (b); i++)
#define repr(i, b, a) for (int i = int(b); i >= (a); i--)
#define all(x) x.begin(), x.end()

const ll mod = 1e9 + 7;
const ll INF = 1e9;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
bool valid(int lx, int ux, int ly, int uy, int x, int y) {
  return lx <= x && x < ux && ly <= y && y < uy;
}
ll power(ll x, ll p) {
  if (p == 0)
    return 1;
  ll res = power(x * x % mod, p / 2);
  if (p % 2 == 1)
    res = res * x % mod;
  return res;
}

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

  rep(i, k) h[i] = 0;
  cout << accumulate(all(h), 0LL) << endl;

  return 0;
}

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

using namespace std;

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, a, b) for (int i = int(a); i < (b); i++)
#define repr(i, b, a) for (int i = int(b); i >= (a); i--)
#define all(x) x.begin(), x.end()

const ll mod = 1e9 + 7;
const ll INF = 1e9;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
bool valid(int lx, int ux, int ly, int uy, int x, int y) {
  return lx <= x && x < ux && ly <= y && y < uy;
}
ll power(ll x, ll p) {
  if (p == 0)
    return 1;
  ll res = power(x * x % mod, p / 2);
  if (p % 2 == 1)
    res = res * x % mod;
  return res;
}

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

  rep(i, min(n, k)) h[i] = 0;
  cout << accumulate(all(h), 0LL) << endl;

  return 0;
}
Problem p02785 (C++)

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

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

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

Fixed submission:
#include <bits/stdc++.h>
#define ll long long int
#define f first
#define s second
using namespace std;

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

int main() {
  fast();
  ll n, k;
  cin >> n >> k;
  vector<ll> v(n);
  for (ll i = 0; i < n; i++)
    cin >> v[i];
  sort(v.begin(), v.end());
  for (ll i = 0, j = n - 1; i < min(k, n); i++, j--) {
    v[j] = 0;
  }
  ll ans = 0;
  for (ll i = 0; i < n; i++)
    ans += v[i];
  cout << ans;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int n, k, a[100001];
long long s;
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n - k; i++) {
    s += a[i];
  }
  cout << s;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int n, k, a[300001];
long long s;
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n - k; i++) {
    s += a[i];
  }
  cout << s;
}
Problem p02785 (C++)

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

  vector<long> health(n);
  for (int i = 0; i < n; i++) {
    cin >> health[i];
  }
  sort(health.begin(), health.end(), greater<int>());
  long long sum = 0LL;

  if (k > 0)
    health.erase(health.begin(), health.begin() + k);

  for (int i = 0; i < health.size(); i++) {
    sum += (long long)health[i];
  }
  cout << sum;
  return 0;
}

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

  vector<long> health(n);
  for (int i = 0; i < n; i++) {
    cin >> health[i];
  }
  sort(health.begin(), health.end(), greater<int>());
  long long sum = 0LL;

  if (k > 0)
    health.erase(health.begin(), health.begin() + min(k, n));

  for (int i = 0; i < health.size(); i++) {
    sum += (long long)health[i];
  }
  cout << sum;
  return 0;
}
Problem p02785 (C++)

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

#define rep(i, p) for (int i = 1; i <= p; i++)
#define ll long long

using namespace std;

int main() {

  ll int N, K;
  ll int kaisu;
  kaisu = 0;
  cin >> N >> K;
  vector<ll int> H;
  ll int x;

  for (int i = 0; i < N; i++) {
    cin >> x;
    H.push_back(x);
    kaisu += x;
  }

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

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

  return 0;
}


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

#define rep(i, p) for (int i = 1; i <= p; i++)
#define ll long long

using namespace std;

int main() {

  ll int N, K;
  ll int kaisu;
  kaisu = 0;
  cin >> N >> K;
  vector<ll int> H;
  ll int x;

  for (int i = 0; i < N; i++) {
    cin >> x;
    H.push_back(x);
    kaisu += x;
  }

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

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

  return 0;
}
Problem p02785 (C++)

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

#define rep2(x, fr, to) for (int(x) = (fr); (x) < (to); (x)++)
#define rep(x, to) for (int(x) = 0; (x) < (to); (x)++)
#define repr(x, fr, to) for (int(x) = (fr); (x) >= (to); (x)--)
#define all(c) (c).begin(), (c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> pii;
const int MD = (int)1e9 + 7;
typedef vector<ll> VL;
void dbg() { cerr << "\n"; }
template <class T, class... T2> void dbg(const T &fst, const T2 &...rst) {
  cerr << fst << ": ";
  dbg(rst...);
}
template <class T> void amax(T &a, T b) {
  if (a > b)
    a = b;
}

int main() {
  // cin.tie(0); ios_base::sync_with_stdio(false);
  int n, k, ans = 0;
  cin >> n >> k;
  VL h(n);
  rep(i, n) cin >> h[i];

  sort(all(h));
  rep(i, k) h[n - 1 - i] = 0;

  ll sm = accumulate(all(h), 0LL);
  cout << sm << "\n";
  return 0;
}


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

#define rep2(x, fr, to) for (int(x) = (fr); (x) < (to); (x)++)
#define rep(x, to) for (int(x) = 0; (x) < (to); (x)++)
#define repr(x, fr, to) for (int(x) = (fr); (x) >= (to); (x)--)
#define all(c) (c).begin(), (c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> pii;
const int MD = (int)1e9 + 7;
typedef vector<ll> VL;
void dbg() { cerr << "\n"; }
template <class T, class... T2> void dbg(const T &fst, const T2 &...rst) {
  cerr << fst << ": ";
  dbg(rst...);
}
template <class T> void amax(T &a, T b) {
  if (a > b)
    a = b;
}

int main() {
  // cin.tie(0); ios_base::sync_with_stdio(false);
  int n, k, ans = 0;
  cin >> n >> k;
  VL h(n);
  rep(i, n) cin >> h[i];

  sort(all(h));
  rep(i, k) if (n - 1 - i >= 0) h[n - 1 - i] = 0;

  ll sm = accumulate(all(h), 0LL);
  cout << sm << "\n";
  return 0;
}
Problem p02785 (C++)

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

int main(void) {
  int n, k, v;
  long long num = 0;
  vector<int> h;

  cin >> n >> k;

  for (int i = 0; i < n; i++) {
    cin >> v;
    h.push_back(v);
  }

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

  for (int i = h.size() - 1; k > 0; i--) {
    h[i] = 0;
    k--;
  }

  for (int i = 0; i < h.size(); i++) {
    num += h[i];
  }

  cout << num << endl;

  return 0;
}

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

int main(void) {
  int n, k, v;
  long long num = 0;
  vector<int> h;

  cin >> n >> k;

  for (int i = 0; i < n; i++) {
    cin >> v;
    h.push_back(v);
  }

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

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

  cout << num << endl;

  return 0;
}
Problem p02785 (C++)

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

#define NREP() for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
using ll = long long;
const static ll MOD = 1e9 + 7;

int main(int argc, char *argv[]) {
  ll n, k;
  cin >> n >> k;
  ll h[n];
  NREP() { cin >> h[i]; }
  sort(h, h + n, greater<>());

  REP(i, k) { h[i] = 0; }

  ll ans = 0;
  NREP() { ans += h[i]; }

  MSG(ans)
}


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

#define NREP() for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
using ll = long long;
const static ll MOD = 1e9 + 7;

int main(int argc, char *argv[]) {
  ll n, k;
  cin >> n >> k;
  ll h[n];
  NREP() { cin >> h[i]; }
  sort(h, h + n, greater<>());

  REP(i, k) {
    if (i >= n)
      break;
    h[i] = 0;
  }

  ll ans = 0;
  NREP() { ans += h[i]; }

  MSG(ans)
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  auto s = 0LL;
  vector<int> H(N);
  for (auto &h : H) {
    cin >> h;
    s += h;
  }
  sort(H.rbegin(), H.rend());
  for (int i = 0; i < K; ++i)
    s -= H[i];
  cout << s << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  auto s = 0LL;
  vector<int> H(N);
  for (auto &h : H) {
    cin >> h;
    s += h;
  }
  sort(H.rbegin(), H.rend());
  for (int i = 0; i < min(K, N); ++i)
    s -= H[i];
  cout << s << endl;
}
Problem p02785 (C++)

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

using namespace std;
typedef long long ll;
const int maxn = 1e5 + 7;
ll a[maxn];
int main() {
  ll n, k, t, s = 0;
  scanf("%lld%lld", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
  }
  sort(a, a + n);
  for (int i = 0; i < n - k; i++)
    s += a[i];
  printf("%lld\n", s);
  return 0;
}


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

using namespace std;
typedef long long ll;
const int maxn = 2e5 + 7;
ll a[maxn];
int main() {
  ll n, k, t, s = 0;
  scanf("%lld%lld", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
  }
  sort(a, a + n);
  for (int i = 0; i < n - k; i++)
    s += a[i];
  printf("%lld\n", s);
  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 < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
typedef long long llong;
const int inf = 1 << 20;
const int mod = 1e9 + 7;

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

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
typedef long long llong;
const int inf = 1 << 20;
const int mod = 1e9 + 7;

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

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

#define int long long int

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

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

  cout << accumulate(arr.begin() + k, arr.end(), 0);
  return 0;
}

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

#define int long long int

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

  vector<int> arr(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  if (k >= n) {
    cout << "0";
  } else {
    sort(arr.begin(), arr.end(), greater<int>());
    cout << accumulate(arr.begin() + k, arr.end(), (int)0);
  }
  return 0;
}
Problem p02785 (C++)

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

int main() {
  ll n, m;
  cin >> n >> m;
  ll arr[100005] = {};
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
  }
  sort(arr, arr + n, greater<ll>());
  for (int i = 0; i < m; i++) {
    sum -= arr[i];
  }
  if (sum <= 0) {
    cout << "0" << endl;
  } else {
    cout << sum << endl;
  }
  return 0;
}


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

int main() {
  ll n, m;
  cin >> n >> m;
  ll arr[300005] = {};
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
  }
  sort(arr, arr + n, greater<ll>());
  for (int i = 0; i < m; i++) {
    sum -= arr[i];
  }
  if (sum <= 0) {
    cout << "0" << endl;
  } else {
    cout << sum << endl;
  }
  return 0;
}
Problem p02785 (Python)

Buggy submission (status: Time Limit Exceeded):
N, K = map(int, input().lower().split())
H = []
total = 0
input_string = input()
H = input_string.split()
H = list(map(int, H))
for j in range(K):
    if not H:
        break
    else:
        H.remove(max(H))
print(sum(H))


Fixed submission:
N, K = map(int, input().lower().split())
H = []
total = 0
input_string = input()
H = input_string.split()
H = list(map(int, H))

H.sort(reverse=True)
del H[0:K]

print(sum(H))
Problem p02785 (C++)

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.rbegin(), a.rend());
  long long ans = 0;
  for (int i = 0; i < k; i++) {
    a[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    ans += a[i];
  }
  cout << ans << '\n';
  return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.rbegin(), a.rend());
  long long ans = 0;
  for (int i = k; i < n; i++) {
    ans += a[i];
  }
  cout << ans << '\n';
  return 0;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()

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

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

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#define MAX_COUNT 200005
#define LL long long
using namespace std;
LL health[MAX_COUNT] = {0};

int partition(int start, int end) {
  int p = start;
  LL pivot = health[end];
  for (int j = start; j < end; ++j) {
    if (health[j] < pivot) {
      LL t = health[j];
      health[j] = health[p];
      health[p] = t;
      p++;
    }
  }
  health[end] = health[p];
  health[p] = pivot;
  return p;
}

void quicksort(int start, int end) {
  if (start < end) {
    LL p = partition(start, end);
    quicksort(start, p - 1);
    quicksort(p + 1, end);
  }
}

int main(int argc, char const *argv[]) {
  int count, specials;
  cin >> count >> specials;
  LL res = 0;
  for (int i = 0; i < count; ++i) {
    cin >> health[i];
  }
  if (count <= specials) {
    cout << 0;
    goto end;
  }
  quicksort(0, count - 1);
  for (int i = 0; i < count - specials; ++i)
    res += health[i];
  cout << res;
end:
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#define MAX_COUNT 200005
#define LL long long
using namespace std;
LL health[MAX_COUNT] = {0};

int partition(int start, int end) {
  int p = start;
  LL pivot = health[end];
  for (int j = start; j < end; ++j) {
    if (health[j] < pivot) {
      LL t = health[j];
      health[j] = health[p];
      health[p] = t;
      p++;
    }
  }
  health[end] = health[p];
  health[p] = pivot;
  return p;
}

void quicksort(int start, int end) {
  if (start < end) {
    LL p = partition(start, end);
    quicksort(start, p - 1);
    quicksort(p + 1, end);
  }
}

int main(int argc, char const *argv[]) {
  int count, specials;
  cin >> count >> specials;
  LL res = 0;
  for (int i = 0; i < count; ++i) {
    cin >> health[i];
  }
  if (count <= specials) {
    cout << 0;
    goto end;
  }
  if (specials == 0) {
    for (int i = 0; i < count; ++i) {
      res += health[i];
    }
    cout << res;
    goto end;
  }
  quicksort(0, count - 1);
  for (int i = 0; i < count - specials; ++i)
    res += health[i];
  cout << res;
end:
  return 0;
}
Problem p02785 (C++)

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

int main() {

  int64_t N, K;
  cin >> N >> K;

  vector<int> H(N);

  for (int64_t i = 0; i < N; i++) {
    int64_t j;
    cin >> j;
    H.at(i) = j;
  }

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

  for (int64_t i = 0; i < K; i++) {
    H.pop_back();
  }

  int64_t h_sum = 0;
  for (auto x : H) {
    h_sum += x;
  }

  cout << h_sum << endl;
}

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

int main() {

  int64_t N, K;
  cin >> N >> K;

  vector<int> H(N);

  for (int64_t i = 0; i < N; i++) {
    int64_t j;
    cin >> j;
    H.at(i) = j;
  }

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

  for (int64_t i = 0; i < K; i++) {
    H.pop_back();
    if (H.size() == 0) {
      break;
    }
  }

  int64_t h_sum = 0;
  for (auto x : H) {
    h_sum += x;
  }

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

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


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

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

int main() {
  long long n, k;
  cin >> n >> k;
  vector<long long> h(n);
  for (auto &e : h)
    cin >> e;
  sort(h.begin(), h.end());
  long long res;
  if (n == k) {
    res = 0;
  } else {
    res = accumulate(begin(h), end(h) - k, 0LL);
  }
  cout << res << endl;
  return 0;
}

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

int main() {
  long long n, k;
  cin >> n >> k;
  vector<long long> h(n);
  for (auto &e : h)
    cin >> e;
  sort(h.begin(), h.end());
  long long res;
  if (n <= k) {
    res = 0;
  } else {
    res = accumulate(begin(h), end(h) - k, 0LL);
  }
  cout << res << endl;
  return 0;
}
Problem p02785 (C++)

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

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

  rep(i, n) cin >> h[i];
  sort(h.begin(), h.end(), greater<ll>());

  ll sum = 0;
  if (n <= k) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = k; k < n; i++) {
    sum += h[i];
  }
  cout << sum << endl;
}

// なぜ？

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

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

  rep(i, n) cin >> h[i];
  sort(h.begin(), h.end(), greater<ll>());

  ll sum = 0;
  if (n <= k) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = k; i < n; i++) {
    sum += h[i];
  }
  cout << sum << endl;
}

// なぜ？
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <random>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)n; i++)

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

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <random>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)n; i++)

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

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

int main() {
  int h;
  int n;
  int sum = 0;
  int a[100000];
  int k;
  int ans;
  cin >> n;
  cin >> k;

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

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

int main() {
  long long int h, n, sum = 0, a[200000], k, ans = 0;
  cin >> n;
  cin >> k;

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