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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define CH(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)

using namespace std;

int N, K, T, U, V, L, D[10010];

int main() {
  cin >> N >> K >> T >> U >> V >> L;
  REP(i, 0, N) cin >> D[i];

  int pos = D[0], vdist = 0, di = 1, keep = 0;
  int diEnd = D[0] + V * T;
  queue<int> dq;

  while (1) {
    REP(nowPos, pos, diEnd + 1) {
      if (nowPos != pos)
        vdist++;
      if (nowPos == L)
        break;
      if (di < N && nowPos == D[di]) {
        if (keep < K)
          keep++, dq.push(di);
        else {
          diEnd = max(nowPos, D[dq.front()]) + V * T;
          dq.pop();
          dq.push(di);
        }
        di++; // uodate next_Di_candidate
      }
      if (nowPos == diEnd && keep > 0) {
        diEnd = max(nowPos, D[dq.front()]) + V * T;
        dq.pop();
        keep--;
      }
    }
    pos = diEnd + 1;
    if (pos >= L)
      break;

    bool flag = true;
    /*always leep is 0 here*/
    REP(nowPos, pos, L + 1) {
      if (di < N && D[di] == nowPos) {
        pos = D[di];
        diEnd = D[di] + V * T;
        di++;
        // use immediately
        flag = false;
        break;
      }
    }
    if (flag)
      break;
  }

  double ans = (double)(L - vdist) / (double)U + (double)vdist / (double)V;
  printf("%.8lf\\n", ans);

  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define CH(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)

using namespace std;

int N, K, T, U, V, L, D[10010];

int main() {
  cin >> N >> K >> T >> U >> V >> L;
  REP(i, 0, N) cin >> D[i];

  int pos = D[0], vdist = 0, di = 1, keep = 0;
  int diEnd = D[0] + V * T;
  queue<int> dq;

  while (1) {
    REP(nowPos, pos, diEnd + 1) {
      if (nowPos != pos)
        vdist++;
      // cout<<"nowPos: "<<nowPos<<", keep: "<<keep<<", nextDi: "<<di<<endl;
      if (nowPos == L)
        break;
      if (di < N && nowPos == D[di]) {
        if (keep < K)
          keep++, dq.push(di);
        else {
          diEnd = max(nowPos, D[dq.front()]) + V * T;
          dq.pop();
          // cout<<"--UseDi -> diEnd: "<<diEnd<<endl;
        }
        di++; // uodate next_Di_candidate
      }
      if (nowPos == diEnd && keep > 0) {
        diEnd = max(nowPos, D[dq.front()]) + V * T;
        dq.pop();
        keep--;
        // cout<<"--UseDi(finish) -> diEnd: "<<diEnd<<endl;
      }
    }
    pos = diEnd + 1;
    if (pos >= L)
      break;

    bool flag = true;
    /*always leep is 0 here*/
    REP(nowPos, pos, L + 1) {
      if (di < N && D[di] == nowPos) {
        pos = D[di];
        diEnd = D[di] + V * T;
        di++;
        // use immediately
        flag = false;
        break;
      }
    }
    if (flag)
      break;
  }

  double ans = (double)(L - vdist) / (double)U + (double)vdist / (double)V;
  printf("%.8lf\\n", ans);

  return 0;
}