Problem p03168 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define fastio                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf pop_front()
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i, a, b) for (lli i = a; i < b; i++)
#define loop(i, a, b) for (int i = a; i < b; i++)
#define mod 1000000007
#define inf 100000000000000000
#define lld long double
#define pll pair<long long int, long long int>
#define vll vector<lli>
#define eps 0.000001
#define endl '\n'
#define mo 998244353

using namespace std;

#define MAXN 200005

typedef tree<lli, null_type, less<lli>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;

lld dp[3001][3001];

int main() {
  ///////////////////////////////////////////
  fastio;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ///////////////////////////////////////////

  lli n;
  cin >> n;

  lld p[n + 1];

  loopl(i, 1, n + 1) cin >> p[i];

  dp[0][0] = 1;

  loopl(i, 1, n + 1) {
    loopl(j, 0, n + 1) {
      if (j > i)
        break;

      dp[i][j] = dp[i - 1][j] * (1 - p[i]);
      if (j >= 1)
        dp[i][j] += dp[i - 1][j - 1] * p[i];
    }
  }

  lld ans = 0;

  loopl(i, n / 2 + 1, n + 1) ans += dp[n][i];

  cout << fixed << setprecision(12) << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define fastio                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf pop_front()
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i, a, b) for (lli i = a; i < b; i++)
#define loop(i, a, b) for (int i = a; i < b; i++)
#define mod 1000000007
#define inf 100000000000000000
#define lld long double
#define pll pair<long long int, long long int>
#define vll vector<lli>
#define eps 0.000001
#define endl '\n'
#define mo 998244353

using namespace std;

#define MAXN 200005

typedef tree<lli, null_type, less<lli>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;

lld dp[3001][3001];

int main() {

  lli n;
  cin >> n;

  lld p[n + 1];

  loopl(i, 1, n + 1) cin >> p[i];

  dp[0][0] = 1;

  loopl(i, 1, n + 1) {
    loopl(j, 0, n + 1) {
      if (j > i)
        break;

      dp[i][j] = dp[i - 1][j] * (1 - p[i]);
      if (j >= 1)
        dp[i][j] += dp[i - 1][j - 1] * p[i];
    }
  }

  lld ans = 0;

  loopl(i, n / 2 + 1, n + 1) ans += dp[n][i];

  cout << fixed << setprecision(12) << ans << endl;
}