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

#include <bits/stdc++.h>
#define int long long
#define INF INT_MAX
using namespace std;

struct isi {
  int zahyou, suberi, mincost;
};
signed main() {
  int a, b;
  while (cin >> a >> b, a | b) {
    vector<isi> c[152][78];
    int d;
    cin >> d;
    for (int e = 0; e < d; e++) {
      isi h;
      h.mincost = 0;
      scanf("%lld%lld", &h.zahyou, &h.suberi);
      c[0][b].push_back(h);
    }
    for (int f = 1; f < a; f++) {
      int g;
      cin >> g;
      for (int h = 0; h < g; h++) {
        int i, j;
        scanf("%lld%lld", &i, &j);
        if (f == 1 && b) {
          isi o;
          o.zahyou = i;
          o.suberi = j;
          o.mincost = 0;
          c[1][b - 1].push_back(o);
        }
        for (int k = b; k >= 0; k--) {
          int m = INF;
          for (int l = 0; l < c[f - 1][k].size(); l++) {
            m = min(m, c[f - 1][k][l].mincost +
                           (c[f - 1][k][l].suberi + j) *
                               abs(c[f - 1][k][l].zahyou - i));
          }
          if (m != INF) {
            isi r;
            r.zahyou = i;
            r.suberi = j;
            r.mincost = m;
            c[f][k].push_back(r);
          }
          if (k != b && f > 1) {
            int m = INF;
            for (int l = 0; l < c[f - 2][k + 1].size(); l++) {
              m = min(m, c[f - 2][k + 1][l].mincost +
                             (c[f - 2][k + 1][l].suberi + j) *
                                 abs(c[f - 2][k + 1][l].zahyou - i));
            }
            if (m != INF) {
              isi r;
              r.zahyou = i;
              r.suberi = j;
              r.mincost = m;
              c[f][k].push_back(r);
            }
          }
        }
      }
    }
    int S = INF;
    for (int p = 0; p <= b; p++) {
      for (isi q : c[a - 1][p]) {
        S = min(S, q.mincost);
      }
    }
    for (int p = 1; p <= b; p++) {
      for (isi q : c[a - 2][p]) {
        S = min(S, q.mincost);
      }
    }
    cout << S << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define int long long
#define INF INT_MAX
using namespace std;

struct isi {
  int zahyou, suberi, mincost;
};
signed main() {
  int a, b;
  while (cin >> a >> b, a | b) {
    vector<isi> c[150][75];
    int d;
    cin >> d;
    for (int e = 0; e < d; e++) {
      isi h;
      h.mincost = 0;
      scanf("%lld%lld", &h.zahyou, &h.suberi);
      c[0][b].push_back(h);
    }
    for (int f = 1; f < a; f++) {
      int g;
      cin >> g;
      for (int h = 0; h < g; h++) {
        int i, j;
        scanf("%lld%lld", &i, &j);
        for (int k = b; k >= 0; k--) {
          int m = INF;
          for (int l = 0; l < c[f - 1][k].size(); l++) {
            m = min(m, c[f - 1][k][l].mincost +
                           (c[f - 1][k][l].suberi + j) *
                               abs(c[f - 1][k][l].zahyou - i));
          }
          if (m != INF) {
            isi r;
            r.zahyou = i;
            r.suberi = j;
            r.mincost = m;
            c[f][k].push_back(r);
          }
          if (k != b && f > 1) {
            int m = INF;
            for (int l = 0; l < c[f - 2][k + 1].size(); l++) {
              m = min(m, c[f - 2][k + 1][l].mincost +
                             (c[f - 2][k + 1][l].suberi + j) *
                                 abs(c[f - 2][k + 1][l].zahyou - i));
            }
            if (m != INF) {
              isi r;
              r.zahyou = i;
              r.suberi = j;
              r.mincost = m;
              c[f][k].push_back(r);
            }
          }
        }
      }
    }
    int S = INF;
    for (int p = 0; p <= b; p++) {
      for (isi q : c[a - 1][p]) {
        S = min(S, q.mincost);
      }
    }
    cout << S << endl;
  }
}