alexjercan/bugnet huggingface dataset:
Problem p02615 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <queue>

using namespace std;

typedef long long ll;
const int N = 200005;

int n;
ll ans;
int w[N];
priority_queue<int> q;

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", w + i);
  sort(w, w + n);
  reverse(w, w + n);
  q.push(w[0]);
  for (int i = 1; i < n; i++) {
    ans += q.top(), q.pop();
    q.push(w[i]), q.push(w[i]);
  }
  printf("%lld\\n", ans);
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <queue>

using namespace std;

typedef long long ll;
const int N = 100005;

int n;
ll ans;
int w[N];
priority_queue<int> q;

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", w + i);
  sort(w, w + n);
  reverse(w, w + n);
  q.push(w[0]);
  for (int i = 1; i < n; i++) {
    ans += q.top(), q.pop();
    q.push(w[i]), q.push(w[i]);
  }
  printf("%lld\\n", ans);
  return 0;
}
Problem p02615 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <random>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using ull = unsigned long long;
const ll K_MAX = 1e5 + 5;
const ll Lmax = ll(1e18);
const ll Nmax = 1e9;
const ll INF = 1e9;

int intpow(int a, int b) {
  int out = 1;
  rep(i, b) { out *= a; }
  return out;
}

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> c(1);
  ll ans = 0;
  rep(i, n) { cin >> a[i]; }

  sort(a.begin(), a.end(), greater<ll>());
  c[0] = a[0];
  for (int i = 1; i < n; i++) {
    c.insert(c.end(), a[i]);
    c.insert(c.end(), a[i]);
    ans += c[i - 1];
  }

  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <random>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using ull = unsigned long long;
const ll K_MAX = 1e5 + 5;
const ll Lmax = ll(1e18);
const ll Nmax = 1e9;
const ll INF = 1e9;

int intpow(int a, int b) {
  int out = 1;
  rep(i, b) { out *= a; }
  return out;
}

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  map<pair<ll, ll>, ll> c;

  ll ans = 0;
  rep(i, n) { cin >> a[i]; }

  sort(a.begin(), a.end(), greater<int>());
  c[make_pair(a[0], a[0])] += 1;

  for (int i = 1; i < n; i++) {
    ll conf = 0;
    pair<ll, ll> pc;
    auto its = c.begin();
    for (auto it = c.begin(); it != c.end(); it++) {
      pair<ll, ll> p = it->first;
      ll np = it->second;
      if (conf < min(p.first, p.second)) {
        its = it;
        conf = min(p.first, p.second);
      }
    }

    pair<ll, ll> ps = its->first;
    ll nps = its->second;

    if (nps <= 1) {
      c.erase(ps);
    } else {
      c[ps] -= 1;
    }
    c[make_pair(ps.first, a[i])] += 1;
    c[make_pair(ps.second, a[i])] += 1;
    ans += conf;
  }

  cout << ans << endl;
}
Problem p02615 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define LAR(a, b) ((a) = max((a), (b)))
#define SML(a, b) ((a) = min((a), (b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template <typename T> using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

ll a[212345];
multiset<pair<ll, ll>, greater<pair<ll, ll>>> st;

int main() {
  int n;
  scanf("%d", &n);
  REP(i, n) scanf("%lld", a + i);
  sort(a, a + n, greater<ll>());
  st.emplace(a[0], a[0]);
  ll ans = 0;
  FOR(i, 1, n) {
    ll b = a[i];
    auto it = st.begin();
    auto [c, d] = *it;
    st.erase(it);
    ans += c;
    st.emplace(min(b, c), max(b, c));
    st.emplace(min(b, d), max(b, d));
    // for(auto [e, f] : st) DEBUG("(%lld, %lld) ", e, f); DEBUG("\\n");
  }
  printf("%lld\\n", ans);
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define LAR(a, b) ((a) = max((a), (b)))
#define SML(a, b) ((a) = min((a), (b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template <typename T> using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

ll a[212345];
multiset<pair<ll, ll>, greater<pair<ll, ll>>> st;

int main() {
  int n;
  scanf("%d", &n);
  REP(i, n) scanf("%lld", a + i);
  sort(a, a + n, greater<ll>());
  st.emplace(a[0], a[0]);
  ll ans = 0;
  FOR(i, 1, n) {
    ll b = a[i];
    auto it = st.begin();
    auto [c, d] = *it;
    st.erase(it);
    ans += c;
    st.emplace(min(b, c), max(b, c));
    st.emplace(min(b, d), max(b, d));
    for (auto [e, f] : st)
      DEBUG("(%lld, %lld) ", e, f);
    DEBUG("\\n");
  }
  printf("%lld\\n", ans);
}
Problem p02615 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI = 3.1415926535897932;

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}

int main() {
  int N;
  cin >> N;
  vector<long long> Ai(N, 0);
  rep(i, N) cin >> Ai.at(i);

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

  ll ans = 0;
  int t = N - 1;
  rep(i, N) {
    int lim = 2;
    if (i == 0)
      lim = 1;
    rep(j, lim) {
      if (t > 0) {
        ans += Ai[i];
        t--;
      }
    }
  }

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI = 3.1415926535897932;

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}

int main() {
  int N;
  cin >> N;
  vector<long long> Ai(N, 0);
  rep(i, N) cin >> Ai.at(i);

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

  ll ans = 0;
  vector<ll> ls;
  ls.push_back(Ai.at(0));
  ls.push_back(Ai.at(1));
  ans += Ai.at(0);

  for (int i = 2; i < N; ++i) {
    ll max_val = 0;
    int idx = 0;
    int diff;
    for (int j = 0; j < ls.size(); ++j) {
      if (j == (ls.size() - 1)) {
        diff = min(ls.at(j), ls.at(0));
      } else {
        diff = min(ls.at(j), ls.at(j + 1));
      }

      if (diff > max_val) {
        max_val = diff;
        idx = j + 1;
      }
    }

    ans += max_val;
    ls.insert(ls.begin() + idx, Ai.at(i));
  }

  cout << ans << endl;
  return 0;
}
Problem p02615 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int N;
  cin >> N;
  int arr[N];
  for (int i = 0; i < N; i++)
    cin >> arr[i];

  sort(arr, arr + N);
  long long ans = arr[N - 1];
  int j = N - 2;
  for (int i = N - 3; i >= 0;) {
    ans += arr[j], --i;
    if (i >= 0)
      ans += arr[j], --i;
    j--;
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int N;
  cin >> N;
  int arr[N];
  for (int i = 0; i < N; i++)
    cin >> arr[i];

  sort(arr, arr + N);
  long long ans = arr[N - 1];
  int j = arr[N - 2];
  for (int i = N - 3; i >= 0;) {
    ans += arr[j], --i;
    if (i >= 0)
      ans += arr[j], --i;
    j--;
  }
  cout << ans << endl;
}
Problem p02615 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int A[200010];
int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A, A + N, greater<int>());
  ll ans = 0;
  for (int i = 1; i < N; i++) {
    ans += A[i / 2];
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int A[100010];
int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A, A + N, greater<int>());
  ll ans = 0;
  for (int i = 1; i < N; i++) {
    ans += A[i - 1];
  }
  cout << ans << endl;
}
Problem p02615 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define arep(i, x, n) for (int i = int(x); i < (int)(n); i++)
#define rep(i, n) for (long long i = 0; i < n; ++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9 + 7
using ll = long long;

int main() {
  ll n;
  cin >> n;
  vector<ll> a;
  rep(i, n) {
    ll num;
    cin >> num;
    a.push_back(num);
  }

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

  vector<pair<ll, ll>> v;
  pair<ll, ll> PAIR1;
  PAIR1.first = a[0];
  PAIR1.second = a[0];
  v.push_back(PAIR1);

  ll score = 0;
  for (ll ii = 1; ii < n; ii++) {
    score += v[ii - 1].first;

    ll fnum = v[ii - 1].first;
    ll snum = v[ii - 1].second;
    pair<ll, ll> pair1;
    pair1.first = a[ii];
    pair1.second = snum;
    v.push_back(pair1);
    pair<ll, ll> pair2;
    pair2.first = a[ii];
    pair2.second = fnum;
    v.push_back(pair2);
  }

  cout << score << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define arep(i, x, n) for (int i = int(x); i < (int)(n); i++)
#define rep(i, n) for (long long i = 0; i < n; ++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9 + 7
using ll = long long;

int main() {
  ll n;
  cin >> n;
  vector<ll> a;
  rep(i, n) {
    ll num;
    cin >> num;
    a.push_back(num);
  }

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

  vector<pair<ll, ll>> v;
  pair<ll, ll> PAIR1;
  PAIR1.first = a[0];
  PAIR1.second = a[0];
  v.push_back(PAIR1);

  ll score = 0;
  for (ll ii = 1; ii < n; ii++) {
    score += v[0].first;

    ll fnum = v[0].first;
    ll snum = v[0].second;
    pair<ll, ll> pair1;
    pair1.first = a[ii];
    pair1.second = snum;
    v.push_back(pair1);
    pair<ll, ll> pair2;
    pair2.first = a[ii];
    pair2.second = fnum;
    v.push_back(pair2);

    v.erase(v.begin());
  }

  cout << score << endl;
}
Problem p02615 (C++) — buggy submission, verdict: Runtime Error

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

// typedef
// -----------------------------------------------------------------------------
typedef long long ll;
typedef long double ld;

// container util
// -----------------------------------------------------------------------------
#define ALL(c) (c).begin(), (c).end()
#define SZ(c) ((ll)(c).size())
#define MAX(c) *max_element(ALL(c))
#define MIN(c) *min_element(ALL(c))
#define SORT(c) sort((c).begin(), (c).end())

// repetition
// -----------------------------------------------------------------------------
#define FOR(i, a, b) for (ll i = (a); i < (ll)(b); ++i)
#define REP(i, n) FOR(i, 0, n)

// constant
// -----------------------------------------------------------------------------
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

// debug
// -----------------------------------------------------------------------------
#define DUMP(x) cerr << #x << " = " << (x) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(15);
  ll N;
  cin >> N;
  vector<ll> A(N);
  REP(i, N) cin >> A[i];
  sort(A.rbegin(), A.rend());
  ll ans = 0;
  FOR(i, 1, N) { ans += A[i / 2]; }
  cout << ans << "\\n";
}

Error: 0

Fixed submission:

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

// typedef
// -----------------------------------------------------------------------------
typedef long long ll;
typedef long double ld;

// container util
// -----------------------------------------------------------------------------
#define ALL(c) (c).begin(), (c).end()
#define SZ(c) ((ll)(c).size())
#define MAX(c) *max_element(ALL(c))
#define MIN(c) *min_element(ALL(c))
#define SORT(c) sort((c).begin(), (c).end())

// repetition
// -----------------------------------------------------------------------------
#define FOR(i, a, b) for (ll i = (a); i < (ll)(b); ++i)
#define REP(i, n) FOR(i, 0, n)

// constant
// -----------------------------------------------------------------------------
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

// debug
// -----------------------------------------------------------------------------
#define DUMP(x) cerr << #x << " = " << (x) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(15);
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i, N) cin >> A[i];
  SORT(A);
  N--;
  int ans = A.back();
  A.pop_back();
  N--;
  while (true) {
    ans += A.back();
    N--;
    if (N == 0)
      break;
    ans += A.back();
    N--;
    if (N == 0)
      break;
    A.pop_back();
  }
  cout << ans << "\\n";
}
Problem p02615 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <vector>

typedef long long ll;
using namespace std;

int main() {
  int N;
  cin >> N;
  int as[N];
  for (int i = 0; i < N; i++) {
    cin >> as[i];
  }
  sort(as, as + N, greater<int>());
  ll total = 0;
  for (int i = 0; i < N - 1; i++) {
    total += as[(i + 1) / 2];
  }
  cout << total << endl;
  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 4) >= this->size() (which is 4)


Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

typedef long long ll;
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<ll> as(N);
  for (int i = 0; i < N; i++) {
    cin >> as.at(i);
  }
  sort(as.begin(), as.end(), greater<int>());
  ll sum = 0;
  for (int i = 1; i < N; i++) {
    sum += as.at(N - (i / 2));
  }
  cout << sum << endl;
}
Problem p02615 (C++) — buggy submission, verdict: Runtime Error

// #include <bits/stdc++.h>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <list>
#include <set>
#include <sstream>
#include <stack>
#include <string>
// #include <array>
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iterator>
#include <map>
#include <memory>
#include <queue>
#include <vector>
using namespace std;
#define FAST_IO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef unsigned int UINT;
typedef unsigned long long ull;
typedef pair<int, int> pdi;
typedef pair<ll, int> pli;

int const maxn = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
inline int lc(int x) { return x << 1; }
inline int rc(int x) { return x << 1 | 1; }

ll a[maxn];

int main(void) {
  FAST_IO;

  int n;
  cin >> n;
  ll ans = 0;
  ll mi = INF;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + 1 + n, [](const int &x, int const &y) { return x > y; });
  for (int i = 2; i <= n; i++) {
    ans += a[(i + 1) / 2];
  }
  cout << ans << endl;

  return 0;
}

Error: 0

Fixed submission:

// #include <bits/stdc++.h>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <list>
#include <set>
#include <sstream>
#include <stack>
#include <string>
// #include <array>
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iterator>
#include <map>
#include <memory>
#include <queue>
#include <vector>
using namespace std;
#define FAST_IO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef unsigned int UINT;
typedef unsigned long long ull;
typedef pair<int, int> pdi;
typedef pair<ll, int> pli;

int const maxn = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
inline int lc(int x) { return x << 1; }
inline int rc(int x) { return x << 1 | 1; }

ll a[maxn];

int main(void) {
  FAST_IO;

  int n;
  cin >> n;
  ll ans = 0;
  ll mi = INF;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    mi = min(mi, a[i]);
    ans += a[i];
  }
  cout << ans - mi << endl;

  return 0;
}
Problem p02615 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) { cin >> a[i]; }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());

  ll ans = 0;
  for (int i = 1; i < n; i++) {
    ans += a[i / 2];
  }
  cout << ans << endl;
  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

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

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> cnt(1000000005, 0);

  rep(i, n) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  sort(a.rbegin(), a.rend());

  ll ans = 0;
  for (ll i = 1; i < n; ++i) {
    if (cnt[a[i - 1]] > 0) {
      ans += a[i - 1];
      cnt[a[i - 1]]--;
    } else {
      ans += a[i];
      cnt[a[i]]--;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02615 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define lli long long int
int main() {
  lli arr[200001], n, sum, current;
  cin >> n;
  for (lli i = 0; i < n; i++)
    cin >> arr[i];
  sort(arr, arr + n);
  sum = arr[n - 1];
  lli j = n - 2;
  lli i = n - 3;
  while (i >= 0) {
    if (i >= 0) {
      sum += arr[j];
      i--;
    }
    if (i >= 0) {
      sum += arr[j];
      i--;
    }
    j--;
  }
  cout << sum;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define lli long long int
bool cmp(int a, int b) {
  if (a >= b)
    return true;
  return false;
}
int main() {
  int n, arr[200001];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr + n, cmp);

  lli sum = arr[0], j = 2, i = 2;
  while (i < n) {
    if (i < n) {
      sum += arr[j];
      i++;
    }
    if (i < n) {
      sum += arr[j];
      i++;
    }
    j++;
  }

  cout << sum;
}
Problem p02615 (C++) — buggy submission, verdict: Runtime Error

// https://atcoder.jp/contests/abc173/tasks/abc173_d
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  for (int i = 0; i < N; ++i)
    cin >> A[i];
  // 降順にソートして、大きい要素から並べる
  std::sort(A.begin(), A.end(), std::greater<ll>());
  ll ans = A[0];
  if (N == 2) {
    cout << ans << endl;
    return 0;
  }

  for (int i = 2; i < N; ++i) {
    ans += A[i / 2];
  }
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

// https://atcoder.jp/contests/abc173/tasks/abc173_d
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  for (int i = 0; i < N; ++i)
    cin >> A[i];
  // 降順にソートして、大きい要素から並べる
  std::sort(A.begin(), A.end(), std::greater_equal<ll>());
  ll ans = A[0];
  if (N == 2) {
    cout << ans << endl;
    return 0;
  }

  for (int i = 2; i < N; ++i) {
    ans += A[i / 2];
  }
  cout << ans << endl;
  return 0;
}
Problem p02615 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// typedef int ll;
typedef long double ld;
#define int ll
#define pb push_back
#define __bp __builtin_popcount
using vint = vector<int>;
using pii = pair<int, int>;
using pdd = pair<ld, ld>;
using vpii = vector<pii>;
#define F first
#define S second
const int N = 2e5 + 5; //(1 << 18) + 5;
// const ll inf = 1e18+7;
const int Inf = 1e9 + 7;
const ld eps = 1e-9;
#ifndef M_PI
#define M_PI 3.1415926535
#endif

void io() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cerr.tie(NULL);
  //	freopen("sweets.in", "r", stdin);
  //	freopen("sweets.out", "w", stdout);
  cout << setprecision(2) << fixed;
}

int n, a[N];

signed main() {
  io();
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a, a + n);
  int sm = 0, idx = 1;
  bool trans = 1;
  for (int i = 1; i < n; ++i) {
    sm += a[n - idx];
    if (trans)
      ++idx;
    trans ^= 1;
  }
  cout << sm;
}

Error: WA

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// typedef int ll;
typedef long double ld;
// #define int ll
#define pb push_back
#define __bp __builtin_popcount
using vint = vector<int>;
using pii = pair<int, int>;
using pdd = pair<ld, ld>;
using vpii = vector<pii>;
#define F first
#define S second
const int N = 1e5 + 5; //(1 << 18) + 5;
// const ll inf = 1e18+7;
const int Inf = 1e9 + 7;
const ld eps = 1e-9;
#ifndef M_PI
#define M_PI 3.1415926535
#endif

void io() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cerr.tie(NULL);
  //	freopen("sweets.in", "r", stdin);
  //	freopen("sweets.out", "w", stdout);
  cout << setprecision(2) << fixed;
}

int n, a[N];

signed main() {
  io();
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a, a + n);
  int sm = 0;
  for (int i = 1; i < n; ++i) {
    sm += a[i];
  }
  cout << sm;
}
Problem p02615 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define lowbit(x) ((x) & (-(x)))
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;
const LL LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;
const int maxn = 2e5 + 10;
int N, A[maxn];
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    scanf("%d", &A[i]);
  }
  sort(A + 1, A + N + 1, greater<int>());
  int cnt = 1;
  LL ans = 0;
  for (int i = 1; i <= N; i++) {
    if (i == 1 || cnt == N - 1) {
      ans += A[i];
      cnt += 1;
    } else {
      ans += A[i] * 2;
      cnt += 2;
    }
    if (cnt == N)
      break;
  }
  printf("%lld\\n", ans);
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define lowbit(x) ((x) & (-(x)))
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;
const LL LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;
const int maxn = 1e5 + 10;
int N, A[maxn];
int main() {
  scanf("%d", &N);
  LL sum = 0;
  int mi = INF;
  for (int i = 1; i <= N; i++) {
    scanf("%d", &A[i]);
    sum += A[i];
    mi = min(mi, A[i]);
  }
  printf("%lld\\n", sum - mi);
  return 0;
}