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

#include <algorithm> // require sort next_permutation count __gcd reverse etc.
#include <cctype>    // require tolower, toupper
#include <cfloat>
#include <climits>
#include <cmath>   // require fabs
#include <cstdio>  // require scanf printf
#include <cstdlib> // require abs exit atof atoi
#include <cstring> // require memset
#include <ctime>   // require srand
#include <deque>
#include <fstream> // require freopen
#include <functional>
#include <iomanip> // require setw
#include <iostream>
#include <limits>
#include <map>
#include <numeric> // require accumulate
#include <queue>
#include <set>
#include <sstream> // require stringstream
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main() {
  //	cut here before submit
  //	freopen ("testcase.RL", "r", stdin );
  string str = "";
  while (getline(cin, str)) {
    if (str.empty())
      break;
    int n = str.length();
    rep(i, n) {
      if (str[i] == ',')
        str[i] = ' ';
    } // end rep
    vector<int> l(12, 0), sum(12, 0);
    int v1, v2;
    stringstream ss(str);
    for (int i = 1; i <= 10; i++) {
      ss >> l[i];
    } // end rep
    l[11] = 100000;
    ss >> v1 >> v2;
    for (int i = 1; i <= 11; i++) {
      sum[i] = sum[i - 1] + l[i];
    } // end for
      /*
                      cerr << "sum: " << endl;
                      rep (i, 10+1 ){
                              cerr << sum[i] << (i != 10 ? ' ' : '\\n' );
                      } // end rep
      */
    double t = (double)sum[10] / (double)(v1 + v2);
    //		cerr << "t: " << t << endl;
    double cl = (double)v1 * t;
    //		cerr << "cl: " << cl << endl;
    int res = 0;
    for (int i = 1; i <= 10; i++) {
      if ((double)sum[i - 1] < cl && cl <= (double)sum[i]) {
        res = i;
        break;
      } // end if
    }   // end for
    printf("%d\\n", res);

  } // end loop

  return 0;
}

Error: WA

Fixed submission:

#include <algorithm> // require sort next_permutation count __gcd reverse etc.
#include <cctype>    // require tolower, toupper
#include <cfloat>
#include <climits>
#include <cmath>   // require fabs
#include <cstdio>  // require scanf printf
#include <cstdlib> // require abs exit atof atoi
#include <cstring> // require memset
#include <ctime>   // require srand
#include <deque>
#include <fstream> // require freopen
#include <functional>
#include <iomanip> // require setw
#include <iostream>
#include <limits>
#include <map>
#include <numeric> // require accumulate
#include <queue>
#include <set>
#include <sstream> // require stringstream
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main() {
  //	cut here before submit
  //	freopen ("testcase.RL", "r", stdin );
  string str = "";
  while (getline(cin, str)) {
    if (str.empty())
      break;
    int n = str.length();
    rep(i, n) {
      if (str[i] == ',')
        str[i] = ' ';
    } // end rep
    vector<int> l(12, 0), sum(12, 0);
    int v1, v2;
    stringstream ss(str);
    for (int i = 1; i <= 10; i++) {
      ss >> l[i];
    } // end rep
    l[11] = 100000;
    ss >> v1 >> v2;
    for (int i = 1; i <= 11; i++) {
      sum[i] = sum[i - 1] + l[i];
    } // end for

    cerr << "sum: " << endl;
    rep(i, 10 + 1) { cerr << sum[i] << (i != 10 ? ' ' : '\\n'); } // end rep

    double t = (double)sum[10] / (double)(v1 + v2);
    cerr << "t: " << t << endl;
    double cl = (double)v1 * t;
    cerr << "cl: " << cl << endl;
    int res = 0;
    for (int i = 1; i <= 10; i++) {
      if (sum[i - 1] < (int)cl && (int)cl <= sum[i]) {
        res = i;
        break;
      } // end if
    }   // end for
    printf("%d\\n", res);

  } // end loop

  return 0;
}