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

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  long long int n, t;
  int q;
  cin >> n >> t >> q;
  vector<long long int> w;

  int home[100005] = {0};

  for (long long int i = 0; i < n; i++) {
    long long int a;
    cin >> a >> home[i];
    w.push_back(a);
  }

  int key[100005] = {0};
  for (int i = 0; i < q; i++) {
    int a;
    cin >> a;
    key[a - 1] = 1;
  }
  int west = 0;

  long long int east2 = 0;
  vector<long long int> talkpoint;
  long long int tp;
  for (long long int i = 0; i < n; i++) {

    if (home[i] == 2) {
      if (west == 0) {

        long long int b = w[i] - t;
        talkpoint.push_back(b);

      } else {
        talkpoint.push_back(tp);
      }
    }
    if (home[i] == 1) {

      if (home[i + 1] == 2) {
        tp = (w[i] + w[i + 1]) / 2;
        for (long long int j = 0; j <= east2; j++) {
          talkpoint.push_back(tp);
        }
        west = 1;
        east2 = 0;
      } else if (i == n - 1) {

        for (long long int j = east2; j >= 0; j--) {
          long long int d = w[i - j] + t;
          talkpoint.push_back(d);
          east2 = 0;
        }

      } else {
        east2++;
        west = 1;
      }
    }
  }
  for (long long int i = 0; i < n; i++) {
    if (key[i] == 1) {

      long long int e;
      if (talkpoint[i] < w[i]) {
        e = w[i] - talkpoint[i];
      } else {
        e = talkpoint[i] - w[i];
      }
      if (e <= t) {
        cout << talkpoint[i] << endl;
      } else {
        if (home[i] == 1) {
          cout << w[i] + t << endl;
        } else {
          cout << w[i] - t << endl;
        }
      }
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  long long int n, t;
  int q;
  cin >> n >> t >> q;
  vector<long long int> w;

  int home[100005] = {0};

  for (long long int i = 0; i < n; i++) {
    long long int a;
    cin >> a >> home[i];
    w.push_back(a);
  }

  int key[100005] = {0};
  for (int i = 0; i < q; i++) {
    int a;
    cin >> a;
    key[a - 1] = 1;
  }
  int west = 0;
  int east = 0;

  long long int east2 = 0;
  vector<long long int> talkpoint;
  long long int tp;
  for (long long int i = 0; i < n; i++) {
    if (i < 50000) {
      if (home[i] == 2) {
        if (west == 0) {

          long long int b = w[i] - t;
          talkpoint.push_back(b);

        } else {
          talkpoint.push_back(tp);

          east = 1;
        }
      }
      if (home[i] == 1) {

        if (home[i + 1] == 2) {
          tp = (w[i] + w[i + 1]) / 2;
          for (long long int j = 0; j <= east2; j++) {
            talkpoint.push_back(tp);
          }
          west = 1;
          east2 = 0;
        } else if (i == n - 1) {
          long long int d = w[i] + t;
          talkpoint.push_back(d);
        } else {
          east2++;
          west = 1;
        }
      }
    }
  }
  for (long long int i = 0; i < n; i++) {
    if (key[i] == 1) {

      long long int e;
      if (talkpoint[i] < w[i]) {
        e = w[i] - talkpoint[i];
      } else {
        e = talkpoint[i] - w[i];
      }
      if (e <= t) {
        cout << talkpoint[i] << endl;
      } else {
        if (home[i] == 1) {
          cout << w[i] + t << endl;
        } else {
          cout << w[i] - t << endl;
        }
      }
    }
  }
  return 0;
}