Problem p01548 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it, X)                                                         \\
  for (__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)
#define ite iterator
#define mp make_pair
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

struct timer {
  time_t start;
  timer() { start = clock(); }
  ~timer() {
    cerr << 1. * (clock() - start) / CLOCKS_PER_SEC << " secs" << endl;
  }
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int, int> pi;
typedef stringstream sst;
typedef vector<int> vint;

int n, m, vi[2010], da[2010], vo[2010];
double prob[2010], probsum[2010];
double vires[2010], dares[2010], vores[2010];

void calc(int stat[], int point, double res[]) {
  rep(i, m + 1) {
    int me = stat[0] * i;
    double dp[4], worst = 1;
    dp[0] = 1;
    dp[1] = dp[2] = 0;
    rep2(j, 1, n) {
      int time = (me + stat[j] - 1) / stat[j];
      double lose;
      if (time > m)
        lose = 0;
      else
        lose = 1 - probsum[time];
      worst *= lose;
      for (int k = 2; k >= 0; k--) {
        dp[k + 1] += dp[k] * lose;
        dp[k] -= dp[k] * lose;
      }
    }
    res[i] = point * (dp[0] + dp[1] + dp[2]) - worst;
  }
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);

  cin >> n >> m;
  rep(i, n) cin >> vi[i] >> da[i] >> vo[i];

  prob[0] = 1;
  rep(i, m) {
    for (int j = i; j >= 0; j--) {
      prob[j + 1] += prob[j] / 3;
      prob[j] -= prob[j] / 3;
    }
  }
  probsum[0] = 0;
  rep(i, m + 1) { probsum[i + 1] = probsum[i] + prob[i]; }

  calc(vi, 5, vires);
  calc(da, 3, dares);
  calc(vo, 2, vores);

  double ans = -INF;
  rep(i, m + 1) rep(j, m - i + 1) {
    int k = m - i - j;
    ans = max(ans, vires[i] + dares[j] + vores[k]);
  }
  cout << fixed << setprecision(16) << ans << endl;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it, X)                                                         \\
  for (__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)
#define ite iterator
#define mp make_pair
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

struct timer {
  time_t start;
  timer() { start = clock(); }
  ~timer() {
    cerr << 1. * (clock() - start) / CLOCKS_PER_SEC << " secs" << endl;
  }
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int, int> pi;
typedef stringstream sst;
typedef vector<int> vint;

int n, m, vi[2010], da[2010], vo[2010];
double prob[10010], probsum[10010];
double vires[2010], dares[2010], vores[2010];

void calc(int stat[], int point, double res[]) {
  rep(i, m + 1) {
    int me = stat[0] * i;
    double dp[4], worst = 1;
    dp[0] = 1;
    dp[1] = dp[2] = 0;
    rep2(j, 1, n) {
      int time = (me + stat[j] - 1) / stat[j];
      double lose = 1 - probsum[time];
      worst *= lose;
      for (int k = 2; k >= 0; k--) {
        dp[k + 1] += dp[k] * lose;
        dp[k] -= dp[k] * lose;
      }
    }
    res[i] = point * (dp[0] + dp[1] + dp[2]) - worst;
  }
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);

  cin >> n >> m;
  rep(i, n) cin >> vi[i] >> da[i] >> vo[i];

  prob[0] = 1;
  rep(i, m) {
    for (int j = i; j >= 0; j--) {
      prob[j + 1] += prob[j] / 3;
      prob[j] -= prob[j] / 3;
    }
  }
  probsum[0] = 0;
  rep(i, 10000) { probsum[i + 1] = probsum[i] + prob[i]; }

  calc(vi, 5, vires);
  calc(da, 3, dares);
  calc(vo, 2, vores);

  double ans = -INF;
  rep(i, m + 1) rep(j, m - i + 1) {
    int k = m - i - j;
    ans = max(ans, vires[i] + dares[j] + vores[k]);
  }
  cout << setprecision(16) << ans << endl;
}