alexjercan/bugnet huggingface dataset:
Problem p00542 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int main(void) {
  int e, f, x, y[4], z, i, j;
  scanf("%d %d %d %d %d %d", &y[0], &y[1], &y[2], &y[3], &e, &f);
  for (i = 0; i < 3; i++) {
    for (j = i + 1; j < 4; j++) {
      if (y[i] < y[j]) {
        z = y[i];
        y[i] = y[j];
        y[j] = z;
      }
    }
  }
  x = y[0] + y[1] + y[2];
  if (e >= f) {
    x = x + e;
    printf("%d\\n", x);
  } else {
    x = x + f;
    printf("%d\\n", x);
  }
  return 0;
}


Error: -11

Fixed submission:

#include <stdio.h>
int main(void) {
  int e, f, x, y[4], z, i, j;
  scanf("%d %d %d %d %d %d", y[0], y[1], y[2], y[3], &e, &f);
  for (i = 0; i < 3; i++) {
    for (j = i + 1; j < 4; j++) {
      if (y[i] < y[j]) {
        z = y[i];
        y[i] = y[j];
        y[j] = z;
      }
    }
  }
  x = y[0] + y[1] + y[2];
  if (e >= f) {
    x = x + e;
    printf("%d\\n", x);
  } else {
    x = x + f;
    printf("%d\\n", x);
  }
  return 0;
}
Problem p00542 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int main(void) {
  int a[6], i, w, x, j;
  for (i = 0; i < 6; i++) {
    scanf("%d", &a[i]);
  }
  for (i = 0; i < 3; i++) {
    for (j = i + 1; j < 4; j++) {
      if (a[i] < a[j]) {
        w = a[i];
        a[i] = a[j];
        a[j] = w;
      }
    }
  }
  if (a[4] > a[5]) {
    x = a[0] + a[1] + a[2] + a[4];
  } else {
    x = a[0] + a[1] + a[2] + a[5];
  }
  printf("%d\\n", x);
  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>
int main(void) {
  int a, b, c, d, e, f, g, h, i, j, x;
  scanf("%d %d %d %d %d %d", &a, &b, &c, &e, &f);
  if (a > b) {
    a = g;
  } else if (a < b) {
    b = g;
  }
  if (b > c) {
    b = h;
  } else if (b < c) {
    c = h;
  }
  if (c > d) {
    c = i;
  } else if (c < d) {
    d = i;
  }
  if (e > f) {
    e = j;
  } else if (e < f) {
    f = j;
  }
  x = g + h + i + j;
  printf("%d\\n", x);
  return 0;
}
Problem p00542 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define GPA 4
#define ROLLMAN endl

using namespace std;
typedef int OTAKU;

OTAKU main() {

  OTAKU roll[GPA], man[GPA];

  for (OTAKU i = 0; i < 4; i++)
    cin >> roll[i];
  for (OTAKU i = 0; i < 2; i++)
    cin >> man[i];

  sort(roll, roll + 4);
  sort(man, man + 2);

  OTAKU Happy_Birthday = 0;

  for (OTAKU i = 3; i > 0; i--)
    Happy_Birthday += roll[i];
  Happy_Birthday += man[1];

  cout << Happy_Birthday << ROLLMAN;
  return GPA - 4;
}

Error: 4

Fixed submission:

#include <bits/stdc++.h>
#define GPA 4
#define ROLLMAN endl

using namespace std;
typedef int OTAKU;

OTAKU main() {

  OTAKU roll[GPA], man[GPA];

  for (OTAKU i = 0; i < 4; i++)
    cin >> roll[i];
  for (OTAKU i = 0; i < 2; i++)
    cin >> man[i];

  sort(roll, roll + 4);
  sort(man, man + 2);

  OTAKU Happy_Birthday = 0;

  for (OTAKU i = 3; i > 0; i--)
    Happy_Birthday += roll[i];
  Happy_Birthday += man[1];

  cout << Happy_Birthday << ROLLMAN;
  return GPA;
}
Problem p00542 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define HAPPY_BIRTHDAY 0
int A, B, C, D, E, F;
int main() {
  cin >> A >> B >> C >> D >> E >> F;
  cout << A + B + C + D - min(min(A, B), min(C, D)) + max(E, F) << endl;
  return HAPPY_BIRTHDAY;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define R cout <<
#define an max(a, n) << endl
int r, o, ll, m, a, n;
int main() {
  cin >> r >> o >> ll >> m >> a >> n;
  sort(&r, &a);
  R + o + ll + m + an;
  return 0;
}
Problem p00544 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

int main() {
  char CHAR[3] = {'B', 'R', 'W'};
  int a, b;
  cin >> a >> b;
  unordered_map<char, int> c[50]{};
  for (int d = 0; d < a; d++) {
    string e;
    cin >> e;
    for (char f : e) {
      for (int g = 0; g < 3; g++) {
        if (CHAR[g] != f)
          c[d][CHAR[g]]++;
      }
    }
  }
  int k = 1 << 29;
  for (int x = 1; x < a - 1; x++) {
    for (int y = 1; y < a - x; y++) {
      int MAX = 0;
      for (int s = 0; s < x; s++)
        MAX += c[s]['W'];
      for (int s = x; s < x + y; s++)
        MAX += c[s]['B'];
      for (int s = x + y; s < a; s++)
        MAX += c[s]['R'];
      k = min(k, MAX);
    }
  }
  cout << k << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  char H[] = {'B', 'R', 'W'};
  int a, b;
  cin >> a >> b;
  map<char, int> c[50];
  for (int d = 0; d < a; d++) {
    string e;
    cin >> e;
    for (char f : e)
      for (int g = 0; g < 3; g++)
        if (H[g] != f)
          c[d][H[g]]++;
  }
  int k = 1 << 29;
  for (int x = 1; x < a - 1; x++)
    for (int y = 1; y < a - x; y++) {
      int M = 0;
      for (int s = 0; s < x; s++)
        M += c[s]['W'];
      for (int s = x; s < x + y; s++)
        M += c[s]['B'];
      for (int s = x + y; s < a; s++)
        M += c[s]['R'];
      k = min(k, M);
    }
  cout << k << endl;
}
Problem p00544 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <stdlib.h>
#include <vector>
using namespace std;

int a, b, ans = 0, W = 0, B = 0, R = 0;

int tansaku(int iti, int ryo, vector<string> c) {
  int kariAns = 0;
  for (int i = 0; i < b; i++) {
    for (int j = 0; j < ryo; j++) {
      if (c[iti + j][i] != 'B')
        kariAns++;
    }
    for (int j = 1; j < iti; j++) {
      if (c[iti - j][i] != 'W')
        kariAns++;
    }
    for (int j = iti + ryo; j < a - 1; j++) {
      if (c[j][i] != 'R')
        kariAns++;
    }
  }
  if (iti + ryo == a - 1) {
    iti = 1;
    ryo++;
  } else {
    iti++;
  }
  if (ryo >= a - 1)
    return kariAns;
  return min(kariAns, tansaku(iti, ryo, c));
}

int main() {
  cin >> a >> b;
  vector<string> c(a);
  for (int i = 0; i < a; i++) {
    cin >> c[i];
  }
  for (int i = 0; i < b; i++) {
    if (c[0][i] != 'W')
      ans++;
    if (c[c.size() - 1][i] != 'R')
      ans++;
  }
  cout << ans + tansaku(1, 1, c) << endl;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <stdlib.h>
#include <vector>
using namespace std;

int a, b, ans = 0, W = 0, B = 0, R = 0;

int tansaku(int iti, int ryo, vector<string> c) {
  int kariAns = 0;
  for (int i = 0; i < b; i++) {
    for (int j = 0; j < ryo; j++) {
      if (c[iti + j][i] != 'B')
        kariAns++;
    }
    for (int j = 1; j < iti; j++) {
      if (c[iti - j][i] != 'W')
        kariAns++;
    }
    for (int j = iti + ryo; j < a - 1; j++) {
      if (c[j][i] != 'R')
        kariAns++;
    }
  }
  if (iti == a - 1) {
    iti = 1;
    ryo++;
  } else {
    iti++;
  }
  if (ryo >= a - 1)
    return kariAns;
  return min(kariAns, tansaku(iti, ryo, c));
}

int main() {
  cin >> a >> b;
  vector<string> c(a);
  for (int i = 0; i < a; i++) {
    cin >> c[i];
  }
  for (int i = 0; i < b; i++) {
    if (c[0][i] != 'W')
      ans++;
    if (c[c.size() - 1][i] != 'R')
      ans++;
  }
  cout << ans + tansaku(1, 1, c) << endl;
}
Problem p00544 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

char S[55][55];

int main() {
  int N, M, i, j, k, c, cnt, row;
  scanf("%d%d", &N, &M);
  for (i = 0; i < N; i++) {
    scanf("%s", S[i]);
  }
  int ans = 999999;
  for (i = 1; i <= N - 2; i++) {
    for (j = 1; i + j <= N - 1; j++) {
      cnt = 0;
      row = 0;
      for (k = 0; k < i; k++) {
        for (c = 0; c < M; c++) {
          if (S[row][c] != 'W')
            cnt++;
        }
        row++;
      }
      for (k = 0; k < j; k++) {
        for (c = 0; c < M; c++) {
          if (S[row][c] != 'B')
            cnt++;
        }
        row++;
      }
      for (k = 0; k < N - i - j; k++) {
        for (c = 0; c < M; c++) {
          if (S[row][c] != 'R')
            cnt++;
        }
        row++;
      }
      if (cnt < ans)
        ans = cnt;
    }
  }
  printf("%d\\n", ans);
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <stdio.h>
using namespace std;
int n;
int m;
int cc;
int ans = 9999;
char c[50][50];
int main() {
  scanf("%d%d", &n, m);
  for (int i = 0; i < n; i++) {
    scanf("%s", &c[i]);
  }
  for (int j = 0; j <= n - 2; j++) {
    if (j == 0) {
      break;
    }
    for (int i = 0; i <= n - j - 1; i++) {
      for (int k = 0; k < j; k++) {
        for (int l = 0; l < m; l++) {
          if (c[k][l] == 'B' || c[k][l] == 'R') {
            cc++;
          }
        }
      }
      for (int k = 0; k < i; k++) {
        if (k < j) {
          break;
        }
        for (int l = 0; l < m; l++) {
          if (c[k][l] == 'W' || c[k][l] == 'R') {
            cc++;
          }
        }
      }
      for (int k = 0; k < n - j - i; k++) {
        if (k < i) {
          break;
        }
        for (int l = 0; l < m; l++) {
          if (c[k][l] == 'W' || c[k][l] == 'B') {
            cc++;
          }
        }
      }
      ans = min(cc, ans);
      cc = 0;
    }
  }
  printf("%d\\n", ans);
}
Problem p00545 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll N, T, Q;
set<ll> S;

ll a[100005];
ll d[100005];

int main() {
  cin >> N >> T >> Q;
  for (int i = 0; i < N; i++) {
    cin >> a[i] >> d[i];
    if (i > 0 && d[i - 1] == 1 && d[i] == 2) {
      S.insert(a[i] / 2LL + a[i - 1] / 2LL);
    }
  }

  ll INF = 1000000000000000001LL;
  S.insert(INF);
  S.insert(-INF);

  for (int i = 0; i < Q; i++) {
    ll id;
    scanf("%lld", &id);
    id--;
    if (d[id] == 1) {
      ll target = *S.lower_bound(a[id]);
      if (abs(target) == INF)
        cout << a[id] + T << endl;
      else
        cout << min(a[id] + T, target) << endl;
    } else {
      set<ll>::iterator it;
      it = S.lower_bound(a[id]);
      it--;
      ll target = *it;
      if (abs(target) == INF)
        cout << a[id] - T << endl;
      else
        cout << max(a[id] - T, target) << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int N, T, Q;
set<ll> S;

ll a[100005];
ll d[100005];

int main() {
  scanf("%lld %lld %lld", &N, &T, &Q);
  for (int i = 0; i < N; i++) {
    scanf("%lld %lld", &a[i], &d[i]);
    if (i && d[i] != d[i - 1]) {
      S.insert(a[i] / 2LL + a[i - 1] / 2LL);
    }
  }

  ll INF = 1000000000000000001LL;
  S.insert(INF);
  S.insert(-INF);

  for (int i = 0; i < Q; i++) {
    ll id;
    scanf("%lld", &id);
    id--;
    if (d[id] == 1) {
      ll target = *S.lower_bound(a[id]);
      cout << min(a[id] + T, target) << endl;
    } else {
      set<ll>::iterator it;
      it = S.lower_bound(a[id]);
      it--;
      ll target = *it;
      cout << max(a[id] - T, target) << endl;
    }
  }
  return 0;
}
Problem p00545 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
long long t, tt;
long long a[100001], s[100001];
int b[100001], flg[100001];
int main(void) {
  int n, q, i, j, c[1000], x;
  scanf("%d %lld %d", &n, &t, &q);
  for (i = 1; i <= n; i++) {
    scanf("%lld %d", &a[i], &b[i]);
    flg[i] = 0;
  }
  for (i = 1; i <= q; i++)
    scanf("%d", &c[i]);
  for (i = 1; i < n; i++) {
    if (b[i] == 1 && b[i + 1] == 2 && a[i + 1] - a[i] < t * 2) {
      flg[i] = 1;
      flg[i + 1] = 1;
      s[i] = s[i + 1] = (a[i] + a[i + 1]) / 2;
    }
  }
  x = 0;
  for (i = n; i >= 1; i--) {
    if (flg[i] == 1) {
      tt = s[i];
      x = 1;
    } else {
      if (b[i] == 1 && x == 1 && a[i] + t > tt) {
        s[i] = tt;
        flg[i] = 2;
      }
    }
  }
  x = 0;
  for (i = 1; i <= n; i++) {
    if (flg[i] == 1) {
      tt = s[i];
      x = 1;
    } else {
      if (b[i] == 2 && x == 1 && a[i] - t < tt) {
        s[i] = tt;
        flg[i] = 2;
      }
    }
  }
  for (i = 1; i <= q; i++) {
    if (flg[c[i]] == 0) {
      if (b[c[i]] == 1)
        s[c[i]] = a[c[i]] + t;
      else
        s[c[i]] = a[c[i]] - t;
    }
  }
  for (i = 1; i <= q; i++)
    printf("%lld\\n", s[c[i]]);
}

Error: -11

Fixed submission:

#include <stdio.h>
long long t, tt;
long long a[100001], s[100001];
int b[100001], flg[100001];
int main(void) {
  int n, q, i, j, c[1000], x;
  scanf("%d %lld %d", &n, &t, &q);
  for (i = 1; i <= n; i++) {
    scanf("%lld %d", &a[i], &b[i]);
    flg[i] = 0;
  }
  for (i = 1; i <= q; i++)
    scanf("%d", &c[i]);
  for (i = 1; i < n; i++) {
    if (b[i] == 1 && b[i + 1] == 2 && a[i + 1] - a[i] < t * 2) {
      flg[i] = 1;
      flg[i + 1] = 1;
      s[i] = s[i + 1] = (a[i] + a[i + 1]) / 2;
    }
  }
  x = 0;
  for (i = n; i >= 1; i--) {
    if (flg[i] == 1) {
      tt = s[i];
      x = 1;
    } else {
      if (b[c[i]] == 1 && x == 1 && a[c[i]] + t > tt) {
        s[c[i]] = tt;
        flg[c[i]] = 2;
      }
    }
  }
  x = 0;
  for (i = 1; i <= n; i++) {
    if (flg[i] == 1) {
      tt = s[i];
      x = 1;
    } else {
      if (b[c[i]] == 2 && x == 1 && a[c[i]] - t < tt) {
        s[c[i]] = tt;
        flg[c[i]] = 2;
      }
    }
  }
  for (i = 1; i <= q; i++) {
    if (flg[c[i]] == 0) {
      if (b[c[i]] == 1)
        s[c[i]] = a[c[i]] + t;
      else
        s[c[i]] = a[c[i]] - t;
    }
  }
  for (i = 1; i <= q; i++)
    printf("%lld\\n", s[c[i]]);
}
Problem p00545 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
long long t, tt;
long long a[100001], s[100001];
int b[100001], flg[100001];
int main(void) {
  int n, q, i, j, c[1000], x;
  scanf("%d %lld %d", &n, &t, &q);
  for (i = 1; i <= n; i++) {
    scanf("%lld %d", &a[i], &b[i]);
    flg[i] = 0;
  }
  for (i = 1; i <= q; i++)
    scanf("%d", &c[i]);
  for (i = 1; i < n; i++) {
    if (b[i] == 1 && b[i + 1] == 2 && a[i + 1] - a[i] < t * 2) {
      flg[i] = 1;
      flg[i + 1] = 1;
      s[i] = s[i + 1] = (a[i] + a[i + 1]) / 2;
    }
  }
  x = 0;
  for (i = n; i >= 1; i--) {
    if (flg[i] == 1) {
      tt = s[i];
      x = 1;
    } else {
      if (b[i] == 1 && x == 1 && a[i] + t > tt) {
        s[i] = tt;
        flg[i] = 2;
      }
    }
  }
  x = 0;
  for (i = 1; i <= n; i++) {
    if (flg[i] == 1) {
      tt = s[i];
      x = 1;
    } else {
      if (b[i] == 2 && x == 1 && a[i] - t < tt) {
        s[i] = tt;
        flg[i] = 2;
      }
    }
  }
  for (i = 1; i <= n; i++) {
    if (flg[i] == 0) {
      if (b[i] == 1)
        s[i] = a[i] + t;
      else
        s[i] = a[i] - t;
    }
  }
  for (i = 1; i <= q; i++)
    printf("%lld\\n", s[c[i]]);
}

Error: -11

Fixed submission:

#include <stdio.h>
long long t, tt;
long long a[100001], s[100001];
int b[100001], flg[100001];
int main(void) {
  int n, q, i, j, c[1000], x;
  scanf("%d %lld %d", &n, &t, &q);
  for (i = 1; i <= n; i++) {
    scanf("%lld %d", &a[i], &b[i]);
    flg[i] = 0;
  }
  for (i = 1; i <= q; i++)
    scanf("%d", &c[i]);
  for (i = 1; i < n; i++) {
    if (b[i] == 1 && b[i + 1] == 2 && a[i + 1] - a[i] < t * 2) {
      flg[i] = 1;
      flg[i + 1] = 1;
      s[i] = s[i + 1] = (a[i] + a[i + 1]) / 2;
    }
  }
  x = 0;
  for (i = n; i > 0; i--) {
    if (flg[c[i]] == 1) {
      tt = s[c[i]];
      x = 1;
    } else {
      if (b[c[i]] == 1 && x == 1 && a[c[i]] + t > tt) {
        s[c[i]] = tt;
        flg[c[i]] = 2;
      }
    }
  }
  x = 0;
  for (i = 1; i <= n; i++) {
    if (flg[c[i]] == 1) {
      tt = s[c[i]];
      x = 1;
    } else {
      if (b[c[i]] == 2 && x == 1 && a[c[i]] - t < tt) {
        s[c[i]] = tt;
        flg[c[i]] = 2;
      }
    }
  }
  for (i = 1; i <= n; i++) {
    if (flg[i] == 0) {
      if (b[i] == 1)
        s[i] = a[i] + t;
      else
        s[i] = a[i] - t;
    }
  }
  for (i = 1; i <= q; i++)
    printf("%lld\\n", s[c[i]]);
}
Problem p00545 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>

constexpr int MAX_N = 100000;
constexpr long long MAX_T = 1000000000000000000;

long long N, T, Q;

long long pos[MAX_N], target[MAX_N];
int dir[MAX_N];
std::vector<long long> stops;

void solve();

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cin >> N >> T >> Q;

  for (int i = 0; i < N; ++i) {
    std::cin >> pos[i] >> dir[i];
  }

  for (int i = 0; i < N - 1; ++i) {
    if (dir[i] == 1 && dir[i + 1] == 2 && (pos[i + 1] - pos[i]) <= (T * 2)) {
      stops.push_back((pos[i + 1] + pos[i]) / 2);
    }
  }

  for (int i = 0; i < Q; ++i) {
    int input;
    std::cin >> input;
    --input;

    long long res = MAX_T;
    if (dir[input] == 1) { // When a citizen heads east.
      auto itr = std::lower_bound(stops.begin(), stops.end(), pos[input]);
      if (itr != stops.end() && *itr <= pos[input] + T) {
        res = *itr;
      }
    } else { // When a citizen heade west.
      auto itr = std::lower_bound(stops.begin(), stops.end(), pos[input] - T);
      while (itr != stops.end() && *itr <= pos[input]) {
        res = *itr;
        ++itr;
      }
    }

    if (res == MAX_T) {
      if (dir[input] == 1) {
        std::cout << pos[input] + T << std::endl;
      } else {
        std::cout << pos[input] - T << std::endl;
      }
    } else {
      std::cout << res << std::endl;
    }
  }

  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

constexpr int MAX_N = 100000;
constexpr long long MAX_T = 1000000000000000000;

long long N, T, Q;

long long pos[MAX_N], target[MAX_N];
int dir[MAX_N];
std::vector<long long> stops;

void solve();

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cin >> N >> T >> Q;

  for (int i = 0; i < N; ++i) {
    std::cin >> pos[i] >> dir[i];
  }

  for (int i = 0; i < N - 1; ++i) {
    if (dir[i] == 1 && dir[i + 1] == 2 && pos[i + 1] - pos[i] <= 2 * T) {
      stops.push_back((pos[i + 1] + pos[i]) / 2);
    }
  }

  for (int i = 0; i < Q; ++i) {
    int input;
    std::cin >> input;
    --input;

    long long res = MAX_T;
    if (dir[input] == 1) { // When a citizen heads east.
      auto itr = std::lower_bound(stops.begin(), stops.end(), pos[input]);
      while (*itr <= pos[input] + T) {
        res = std::min(res, *itr);
        ++itr;
      }
    } else { // When a citizen heade west.
      auto itr = std::lower_bound(stops.begin(), stops.end(), pos[input] - T);
      while (*itr <= pos[input]) {
        res = std::min(res, *itr);
        ++itr;
      }
    }

    if (res == MAX_T) {
      if (dir[input] == 1) {
        std::cout << pos[input] + T;
      } else {
        std::cout << pos[input] - T;
      }
    } else {
      std::cout << res << std::endl;
    }
  }

  return 0;
}
Problem p00545 (C++) — buggy submission, verdict: Runtime Error

//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
// 1. dp?????????
ll dp[100001];
// 2. n?????????
ll N, T, Q;
ll A[100001];
int D[100001];

// 7. calc?????????
ll calc(int k) {
  // 8. dp???????????°??????
  if (dp[k] != A[k])
    return dp[k];
  // 9. dp????¨????

  if (D[k] == 1) {
    if (D[k + 1] == 1) {
      dp[k] = min(A[k] + T, calc(k + 1));
    } else {
      dp[k] = min((A[k] + A[k + 1]) / 2, A[k] + T);
    }
  }
  if (D[k] == 2) {
    if (D[k - 1] == 2) {
      dp[k] = max(A[k] - T, calc(k - 1));
    } else {
      dp[k] = max((A[k] + A[k - 1]) / 2, A[k] - T);
    }
  }

  return dp[k];
}
int main() {
  cin >> N >> T >> Q;

  // 3.?????????

  // 4.??\\???
  for (int i = 1; i < N + 1; i++) {
    cin >> A[i] >> D[i];
    dp[i] = A[i];
  }

  // 5.???????????¨???

  if (D[1] == 2) {
    dp[1] -= T;
  }

  if (D[N] == 1) {
    dp[N] += T;
  }

  // 6.??????
  int X;
  for (int i = 1; i < Q + 1; i++) {
    cin >> X;
    cout << calc(X) << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
// 1. dp?????????
ll dp[100001];
// 2. n?????????
ll N, T, Q;
ll A[10001];
int D[10001];

// 7. calc?????????
ll calc(int k) {
  // 8. dp???????????°??????
  if (dp[k] != A[k])
    return dp[k];
  // 9. dp????¨????

  if (D[k] == 1) {
    if (D[k + 1] == 1) {
      dp[k] = min(A[k] + T, calc(k + 1));
    } else {
      dp[k] = min((A[k] + A[k + 1]) / 2, A[k] + T);
    }
  }
  if (D[k] == 2) {
    if (D[k - 1] == 2) {
      dp[k] = max(A[k] - T, calc(k - 1));
    } else {
      dp[k] = max((A[k] + A[k - 1]) / 2, A[k] - T);
    }
  }

  return dp[k];
}
int main() {
  cin >> N >> T >> Q;

  // 3.?????????

  // 4.??\\???
  for (int i = 1; i < N + 1; i++) {
    cin >> A[i] >> D[i];
    dp[i] = A[i];
  }

  // 5.???????????¨???

  if (D[1] == 2) {
    dp[1] -= T;
  }

  if (D[N] == 1) {
    dp[N] += T;
  }

  // 6.??????
  int X;
  for (int i = 1; i < Q + 1; i++) {
    cin >> X;
    cout << calc(X) << endl;
  }

  return 0;
}
Problem p00545 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>

#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

typedef long long ll;

int n;
ll t;
int q;
ll a[100000];
int d[100000];
int x[1000];

int main() {
  scanf("%d%lld%d", &n, &t, &q);
  rep(i, n) { scanf("%lld%d", &a[i], &d[i]); }
  rep(i, q) { scanf("%d", &x[i]); }

  int i = 0;
  while (i < n && d[i] == 2) {
    a[i++] -= t;
  }
  while (i < n) {
    int j = 0;
    while (i + j < n && d[i + j] == 1) {
      ++j;
    }
    int k = 0;
    while (i + j + k < n && d[i + j + k] == 2) {
      ++k;
    }
    if (k == 0) {
      rep(z, j) { a[i + z] += t; }
    } else {
      ll p = (a[i + j - 1] + a[i + j]) / 2;
      rep(z, j) { a[i + z] = min(a[i + z] + t, p); }
      rep(z, k) { a[i + j + z] = max(a[i + j + z] - t, p); }
    }
    i += j + k;
  }

  rep(i, q) { printf("%lld\\n", a[x[i] - 1]); }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>

#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

typedef long long ll;

int n;
ll t;
int q;
ll a[100000];
int d[100000];
int x[1000];

int main() {
  scanf("%d%lld%d", &n, &t, &q);
  rep(i, n) { scanf("%lld%d", &a[i], &d[i]); }
  rep(i, q) { scanf("%d", &x[i]); }

  int i = 0;
  while (i < n && d[i] == 2) {
    a[i] -= t;
  }
  while (i < n) {
    int j = 0;
    while (i + j < n && d[i + j] == 1) {
      ++j;
    }
    int k = 0;
    while (i + j + k < n && d[i + j + k] == 2) {
      ++k;
    }
    if (k == 0) {
      rep(z, j) { a[i + z] += t; }
    } else {
      ll p = (a[i + j - 1] + a[i + j]) / 2;
      rep(z, j) { a[i + z] = min(a[i + z] + t, p); }
      rep(z, k) { a[i + j + z] = max(a[i + j + z] - t, p); }
    }
    i += j + k;
  }

  rep(i, q) { printf("%lld\\n", a[x[i] - 1]); }
  return 0;
}