Problem p02888 (C++)

Buggy submission (status: Runtime Error):
// #pragma GCC optimize("Ofast")

#pragma GCC optimize("O3")
#pragma GCC target("avx,avx2,fma")
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i, a, b) for (ll i = (ll)a; i < (ll)b; i += 1)
#define rf(i, a, b) for (ll i = (ll)a; i >= (ll)b; i -= 1)
#define endl '\n'
#define N 1000000007 // prime modulo value
#define M 998244353
#define all(x) x.begin(), x.end()
using namespace std;
// From Geeksforgeeks
inline ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
// Power function took from geeksforgeeks
ll power(ll x, ll y) {
  ll res = 1;

  x = x % N;
  if (x == 0)
    return 0;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % N;
    y = y >> 1;
    x = (x * x) % N;
  }
  return res;
}
double dist(ll x1, ll y1, ll x2, ll y2) {
  double ans = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ll n;
  cin >> n;
  vector<ll> arr(n, 0);
  f(i, 0, n) { cin >> arr[i]; }
  sort(all(arr));
  ll ans = 0;
  f(i, 0, n) {
    f(j, i + 1, n) {
      f(k, j + 1, n) {
        if (arr[k] < arr[i] + arr[j]) {
          ans += 1;
        }
      }
    }
  }
  cout << ans;
  return 0;
}


Fixed submission:
// #pragma GCC optimize("Ofast")

// #pragma GCC optimize("O3")
#pragma GCC target("avx,avx2,fma")
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i, a, b) for (ll i = (ll)a; i < (ll)b; i += 1)
#define rf(i, a, b) for (ll i = (ll)a; i >= (ll)b; i -= 1)
#define endl '\n'
#define N 1000000007 // prime modulo value
#define M 998244353
#define all(x) x.begin(), x.end()
using namespace std;
// From Geeksforgeeks
inline ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
// Power function took from geeksforgeeks
ll power(ll x, ll y) {
  ll res = 1;

  x = x % N;
  if (x == 0)
    return 0;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % N;
    y = y >> 1;
    x = (x * x) % N;
  }
  return res;
}
double dist(ll x1, ll y1, ll x2, ll y2) {
  double ans = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ll n;
  cin >> n;
  vector<ll> arr(n, 0);
  f(i, 0, n) { cin >> arr[i]; }
  sort(all(arr));
  ll ans = 0;
  f(i, 0, n) {
    f(j, i + 1, n) {
      f(k, j + 1, n) {
        if (arr[k] < arr[i] + arr[j]) {
          ans += 1;
        }
      }
    }
  }
  cout << ans;
  return 0;
}