Problem p02785 (C++)

Buggy submission (status: Runtime Error):
/*
    NEVER GIVE UP!
    THE EXPERT IN ANYTHING WAS ONCE A BEGINNER
*/

#pragma GCC optimize("unroll-loops", "omit-frame-pointer", "inline")
#pragma GCC option("arch=native", "tune=native", "no-zero-upper")
#pragma GCC target(                                                            \
    "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
using namespace std;
#define FIO                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define f(i, a, b) for (ll i = a; i <= b; i++)
#define fi(i, a, b) for (ll i = a; i >= b; i--)
#define fa(x, b) for (auto x : b)
#define TC                                                                     \
  ll test_case;                                                                \
  cin >> test_case;                                                            \
  for (ll number = 1; number <= test_case; number++)
#define vll vector<ll>
#define pb push_back
#define pll pair<ll, ll>
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (ll)(a).size()
#define sp(x) cout << fixed << setprecision(x);
#define ReadFile freopen("input.txt", "r", stdin)
#define WriteFile freopen("output.txt", "w", stdout)
#define endl "\n"

const ld pi = acos(-1);
const ll M = 1e9 + 7, N = 1e7 + 5, INF = 1e18;

void solve() {
  ll k, n, s = 0;
  cin >> n >> k;
  vll a(n);

  f(i, 0, n - 1) cin >> a[i];

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

  f(i, k, n - 1) s += a[i];

  cout << s;
}

int32_t main() {
  FIO solve();
  return 0;
}

Fixed submission:
/*
    NEVER GIVE UP!
    THE EXPERT IN ANYTHING WAS ONCE A BEGINNER
*/

#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
using namespace std;
#define FIO                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define f(i, a, b) for (ll i = a; i <= b; i++)
#define fi(i, a, b) for (ll i = a; i >= b; i--)
#define fa(x, b) for (auto x : b)
#define TC                                                                     \
  ll test_case;                                                                \
  cin >> test_case;                                                            \
  for (ll number = 1; number <= test_case; number++)
#define vll vector<ll>
#define pb push_back
#define pll pair<ll, ll>
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (ll)(a).size()
#define sp(x) cout << fixed << setprecision(x);
#define ReadFile freopen("input.txt", "r", stdin)
#define WriteFile freopen("output.txt", "w", stdout)
#define endl "\n"

const ld pi = acos(-1);
const ll M = 1e9 + 7, N = 1e7 + 5, INF = 1e18;

void solve() {
  ll k, n, s = 0;
  cin >> n >> k;
  vll a(n);

  f(i, 0, n - 1) cin >> a[i];

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

  f(i, k, n - 1) s += a[i];

  cout << s;
}

int32_t main() {
  FIO solve();
  return 0;
}