alexjercan/bugnet huggingface dataset:
Problem p01359 (C++) — buggy submission, verdict: Memory Limit Exceeded


#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

#define pb push_back
typedef long long ll;
typedef complex<int> P;

struct st {
  string name;
  int be;
  int en;
  st() {}
  st(string str, int y, int n) {
    name = str;
    be = y - n + 1;
    en = y;
  }
};

bool inRange(int a, int b, int c) { return a <= b && b <= c; }

bool solve() {
  int n, q;
  cin >> n >> q;
  if (n == 0 && q == 0)
    return false;

  vector<st> vst;
  for (int i = 0; i < n; i++) {
    int by, wy;
    string str;
    cin >> str >> by >> wy;
    st tmp(str, wy, by);
    vst.pb(tmp);
  }

  for (int i = 0; i < q; i++) {
    int in;
    cin >> in;
    bool flg = false;
    for (int j = 0; j < vst.size(); j++) {
      if (inRange(vst[j].be, in, vst[j].en)) {
        cout << vst[j].name << " " << in - vst[j].be + 1 << endl;
        flg = true;
        break;
      }
    }
    if (!flg)
      cout << "Unknown" << endl;
  }

  return true;
}

int main() {
  cout.setf(ios::fixed);
  cout.precision(10);

  while (solve())
    ;

  return 0;
}


Error: MLE

Fixed submission:


#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

#define pb push_back
typedef long long ll;
typedef complex<int> P;

bool solve() {
  int n, q;
  cin >> n >> q;
  if (n == 0 && q == 0)
    return false;

  map<int, pair<string, int>> m;
  for (int i = 0; i < n; i++) {
    int by, wy;
    string str;
    cin >> str >> by >> wy;
    for (int j = 0; j < by; j++) {
      m[wy - j] = make_pair(str, by - j);
    }
  }

  for (int i = 0; i < q; i++) {
    int in;
    cin >> in;
    if (m.count(in)) {
      cout << m[in].first << " " << m[in].second << endl;
    } else {
      cout << "Unknown" << endl;
    }
  }

  return true;
}

int main() {
  cout.setf(ios::fixed);
  cout.precision(10);

  while (solve())
    ;

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

#include <iostream>

using namespace std;

const int MAX_N = 1000 + 5;
int era_y[MAX_N], wes_y[MAX_N];
string name[MAX_N];

int main() {
  int N, Q;

  while (cin >> N >> Q, N || Q) {
    for (int i = 0; i < N; i++)
      cin >> name[i] >> era_y[i] >> wes_y[i];

    for (int i = 0; i < Q; i++) {
      int q;

      cin >> q;
      bool flag = false;
      for (int j = 0; j < N; j++) {
        if (wes_y[j] - era_y[j] + 1 <= q && q <= wes_y[j]) {
          flag = true;
          cout << name[j] << " " << q - (wes_y[j] - era_y[j]) << endl;
          break;
        }
      }

      if (!flag) {
        cout << "Unknown" << endl;
      }
    }
  }

  return 0;
}

Error: 0
4 3
meiji 10 1877
taisho 6 1917
showa 62 1987
heisei 22 2010
1868
1917
1988
1 1
universalcentury 123 2168
2010


Fixed submission:

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

using namespace std;

int main() {
  int N, Q;

  while (cin >> N >> Q, N || Q) {
    cerr << N << " " << Q << endl;
    vector<pair<int, string>> memo;

    for (int i = 0; i < N; i++) {
      string s;
      int ey, wy;

      cin >> s >> ey >> wy;
      cerr << s << " " << ey << " " << wy << endl;
      memo.push_back(make_pair(wy - ey, s));
    }
    sort(memo.begin(), memo.end());

    for (int i = 0; i < Q; i++) {
      int q;

      cin >> q;
      cerr << q << endl;
      bool flag = false;
      vector<pair<int, string>>::iterator it = memo.begin();

      while (it != memo.end()) {
        if ((*it).first > q && memo.size() > 1) {
          advance(it, -1);
          flag = true;
          cout << (*it).second << " " << q - (*it).first << endl;
          break;
        }

        it++;
      }
      if (!flag)
        cout << "Unknown" << endl;
    }
  }

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

#include <stdio.h>
#include <string.h>

int main(void) {
  int es[1000], eg[1000], eby, wy, n, q, i, j, query;
  char name[1000][18], c;
  while (1) {
    scanf("%d%d%*c", &n, &q);
    if (n == 0 && q == 0)
      break;
    for (i = 0; i < n; i++) {
      j = 0;
      while ((c = getchar()) != ' ')
        name[i][j++] = c;
      name[i][j] = '\\0';
      scanf("%d%d%*c", &eby, &eg[i]); // eby <= wy
      eg[i]--;
      es[i] = eg[i] - eby + 1;
    }
    for (i = 0; i < q; i++) {
      scanf("%d%*c", &query);
      query--;
      for (j = 0; j < n; j++) {
        if (es[j] <= query && query <= eg[j])
          break;
      }
      if (j != n)
        printf("%s %d\\n", name[j], query - es[j] + 1);
      else
        printf("Unknown\\n");
    }
  }
  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>
#include <string.h>
#define MAXNUM 1000000000

int main(void) {
  int es[MAXNUM], eg[MAXNUM], eby, wy, n, q, i, j, query;
  char name[1000][18], c;
  while (1) {
    scanf("%d%d%*c", &n, &q);
    if (n == 0 && q == 0)
      break;
    for (i = 0; i < n; i++) {
      j = 0;
      while ((c = getchar()) != ' ')
        name[i][j++] = c;
      name[i][j] = '\\0';
      scanf("%d%d%*c", &eby, &eg[i]); // eby <= wy
      eg[i]--;
      es[i] = eg[i] - eby + 1;
    }
    for (i = 0; i < q; i++) {
      scanf("%d%*c", &query);
      query--;
      for (j = 0; j < n; j++) {
        if (es[j] <= query && query <= eg[j])
          break;
      }
      if (j != n)
        printf("%s %d\\n", name[j], query - es[i] + 1);
      else
        printf("Unknown\\n");
    }
  }
  return 0;
}
Problem p01359 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

typedef long long int lli;

int main(void) {
  while (1) {
    vector<pair<lli, string>> dict;
    map<string, lli> max;
    int n, q;
    cin >> n >> q;
    if (!n)
      break;

    for (int i = 0; i < n; i++) {
      string name;
      lli base, west;
      cin >> name >> base >> west;
      dict.push_back(pair<lli, string>(west - base + 1, name));
      max[name] = base;
    }
    sort(begin(dict), end(dict));
    for (int i = 0; i < q; i++) {
      lli y;
      cin >> y;
      auto it = upper_bound(begin(dict), end(dict),
                            pair<lli, string>(y, string("\\xFF")));

      if (it == dict.end())
        it = dict.begin() + (dict.size() - 1);
      else if (it == dict.begin()) {
        cout << "Unknown" << endl;
        continue;
      } else
        it--;

      if ((y - it->first + 1) > max[it->second])
        cout << "Unknown" << endl;
      else
        cout << it->second << ' ' << y - (it->first) + 1 << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main(void) {
  while (1) {
    map<int, string> dict;
    map<string, int> max;
    int n, q;
    cin >> n >> q;
    if (!n)
      break;

    auto last = dict.begin();
    for (int i = 0; i < n; i++) {
      string name;
      int base, west;
      cin >> name >> base >> west;
      dict[west - base + 1] = name;
      max[name] = base;
      if (last->first > west - base + 1)
        last = dict.find(west - base + 1);
    }
    for (int i = 0; i < q; i++) {
      int y;
      cin >> y;
      auto it = dict.upper_bound(y);
      if (it == dict.end())
        it = last;
      else if (it == dict.begin()) {
        cout << "Unknown" << endl;
        continue;
      } else
        it--;

      if ((y - it->first + 1) > max[it->second])
        cout << "Unknown" << endl;
      else
        cout << it->second << ' ' << y - (it->first) + 1 << endl;
    }
  }
  return 0;
}
Problem p01359 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

struct D {
  bool operator<(const D &rhs) { return e < rhs.e; }
  int s, e;
  string name;
};

int main(void) {
  while (1) {
    int n, q;
    cin >> n >> q;
    if (!n && !q)
      break;

    vector<D> data(n);
    for (int i = 0; i < n; i++) {
      int a, b;
      cin >> data[i].name >> a >> b;
      data[i].s = b - a + 1;
      data[i].e = b;
    }
    sort(data.begin(), data.end());

    for (int i = 0; i < q; i++) {
      int x;
      cin >> x;

      for (int j = 0; j < n; j++) {
        if (data[j].s <= x && data[j].e >= x) {
          cout << data[j].name << " " << x - data[j].s + 1 << endl;
          j = n;
          break;
        }
        if (j == n - 1)
          cout << "Unknown" << endl;
      }
    }
  }
}

Error: TLE

Fixed submission:

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

struct D {
  int ey, wy;
  string s;
  D(){};
  D(int _ey, int _wy, string _s) { ey = _ey, wy = _wy, s = _s; };
  bool operator<(const D &rhs) { return wy < rhs.wy; }
};
int n, q;
int y[1010];

int b_serch(int l, int r, int num) {
  int c = (l + r) / 2;
  if (y[c] == num)
    return c;
  else if (y[c] > num)
    return b_serch(c, r, num);
  else
    return b_serch(l, c, num);
}

int main(void) {
  while (1) {
    cin >> n >> q;
    if (!n && !q)
      break;
    vector<D> data(n);
    int _ey, _wy;
    string _s;
    D _data;
    for (int i = 0; i < n; i++) {
      cin >> _s >> _ey >> _wy;
      D _data(_ey, _wy, _s);
      y[i] = _wy;
      data[i] = _data;
    }
    sort(y, y + n);
    sort(data.begin(), data.end());

    for (int i = 0; i < q; i++) {
      int x;
      cin >> x;
      int *it = lower_bound(y, y + n, x);
      // cout << *it << endl;
      int idx;
      if (y[0] == *it)
        idx = 0;
      else if (y[n - 1] == *it)
        idx = n - 1;
      else
        idx = b_serch(0, n - 1, *it);
      // cout << idx << endl;

      int ini = data[idx].wy - data[idx].ey;
      if (x > ini && x <= data[idx].wy)
        cout << data[idx].s << " " << x - ini << endl;
      else
        cout << "Unknown" << endl;
    }
  }

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
#define inf 1e9
#define eps 1e-8
#define MAXT 500000
#define MAXN 1010
using namespace std;

int n, q;
struct Node {
  char nam[20];
  int st, ed;
  int id;
} a[MAXN];
int main() {
  while (scanf("%d%d", &n, &q)) {
    if (n == 0 && q == 0)
      break;
    for (int i = 1; i <= n; i++) {
      scanf("%s", a[i].nam);
      int x, y;
      scanf("%d%d", &x, &y);
      a[i].st = y - x + 1;
      a[i].ed = y;
    }
    while (q--) {
      int tp;
      scanf("%d", &tp);
      int flag = 0;
      for (int i = 1; i <= n; i++) {
        if (tp >= a[i].st && tp <= a[i].ed) {
          printf("%s %d\\n", a[i].nam, tp - a[i].st + 1);
          flag = 1;
          break;
        }
      }
      if (!flag)
        printf("Unknown\\n");
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

char s[100010];
int len;
int pos[20] = {0, 0, 1, 2, 0, 1, 2, 0, 1, 2};

int dp[2][10][10][2];
int cost(int x, int y) {
  if (x == 5 || y == 5)
    return 0;
  if (pos[x] - pos[y] > 0)
    return 1;
  return 0;
}
int main() {
  freopen("/home/lovezzt/桌面/in.txt", "r", stdin);
  while (1) {
    scanf("%s", s);
    if (s[0] == '#')
      break;
    len = strlen(s);
    memset(dp[0], 60, sizeof(dp[0]));
    dp[0][5][5][0] = dp[0][5][5][1] = 0;
    bool p = 0, q = 1;
    for (int i = 0; i < len; ++i) {
      memset(dp[q], 60, sizeof(dp[q]));
      for (int j = 0; j < 10; ++j) {
        for (int k = 0; k < 10; ++k) {
          for (int l = 0; l < 2; ++l) {
            if (dp[p][j][k][l] > len)
              continue;
            int pos = s[i] - '0';
            if (l == 0) {
              dp[q][pos][k][0] =
                  min(dp[q][pos][k][0], dp[p][j][k][l] + 1 + cost(pos, k));
              dp[q][j][pos][1] =
                  min(dp[q][j][pos][1], dp[p][j][k][l] + cost(j, pos));
            } else {
              dp[q][pos][k][0] =
                  min(dp[q][pos][k][0], dp[p][j][k][l] + cost(pos, k));
              dp[q][j][pos][1] =
                  min(dp[q][j][pos][1], dp[p][j][k][l] + 1 + cost(j, pos));
            }
          }
        }
      }
      p = q;
      q = !q;
    }
    int ans = 0x3fffffff;
    for (int j = 0; j < 10; ++j) {
      for (int k = 0; k < 10; ++k) {
        for (int l = 0; l < 2; ++l) {
          ans = min(dp[p][j][k][l], ans);
        }
      }
    }
    printf("%d\\n", ans);
  }
  return 0;
}
Problem p01359 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
using namespace std;
int N, Q, v[1000], w[1000], x;
string s[1000];
int main() {
  while (cin >> N >> Q, N | Q) {
    for (int i = 0; i < N; i++)
      cin >> s[i] >> v[i] >> w[i];
    for (int i = 0; i < Q; i++) {
      cin >> x;
      int f = 0;
      for (int j = 0; j < N; j++) {
        if (w[j] - v[j] < x && x <= w[j]) {
          cout << s[j] << ' ' << x - w[j] + v[j] << endl;
          f = 1;
          break;
        }
      }
      if (!f)
        cout << "Unknown" << endl;
    }
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#pragma warning(disable : 4996)
using namespace std;
int N, Q, A, B, R;
pair<int, string> D[1000];
int main() {
  while (true) {
    scanf("%d%d", &N, &Q);
    if (N == 0 && Q == 0)
      break;
    for (int i = 0; i < N; i++)
      cin >> D[i].second >> A >> B, D[i].first = B - A;
    sort(D, D + N);
    for (int i = 0; i < Q; i++) {
      scanf("%d", &R);
      bool flag = false;
      for (int j = N - 1; j >= 0; j++) {
        if (D[i].first < R) {
          printf("%s %d\\n", D[i].second.c_str(), R - D[i].first);
          flag = true;
          break;
        }
      }
      if (!flag) {
        printf("Unknown\\n");
      }
    }
  }
  return 0;
}
Problem p01359 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <complex>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
typedef long long ll;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define EACH(i, c)                                                             \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
using namespace std;

struct Era {
  string name;
  int base, len;
};

int main() {

  int n, q;

  while (cin >> n >> q, n | q) {
    string s;
    int base, wes;
    vector<Era> v;
    REP(i, n) {
      cin >> s >> base >> wes;
      Era e;
      e.name = s;
      e.base = base;
      e.len = wes;
      v.push_back(e);
    }

    int query;
    REP(i, q) {
      cin >> query;
      for (int j = 0; j < v.size(); ++j) {
        if (v[j].len - v[j].base + 1 <= query && v[j].len >= query) {
          cout << v[j].name << " " << query - (v[j].len - v[j].base) << endl;
          goto NEXT;
        }
      }
      cout << "Unknown" << endl;
    NEXT:;
    }
  }
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <complex>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
typedef long long ll;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define EACH(i, c)                                                             \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
using namespace std;

struct Era {
  string name;
  int base, len;
};

int main() {
  ifstream ifs("A.txt");
  ofstream ofs();
  int n, q;

  while (ifs >> n >> q, n | q) {
    string s;
    int base, wes;
    vector<Era> v;
    REP(i, n) {
      ifs >> s >> base >> wes;
      Era e;
      e.name = s;
      e.base = base;
      e.len = wes;
      v.push_back(e);
    }

    int query;
    REP(i, q) {
      ifs >> query;
      // cout<<"query "<<query<<endl;
      for (int j = 0; j < v.size(); ++j) {
        if (v[j].len - v[j].base + 1 <= query && v[j].len >= query) {
          cout << v[j].name << " " << query - (v[j].len - v[j].base) << endl;

          // cout<<v[j].len<<" "<<v[j].base<<endl;
          goto NEXT;
        }
        // cout<<v[j].name<<" "<<query<<" "<<v[j].len-base+1<<"
        // "<<v[j].len<<endl;
      }
      cout << "Unknown" << endl;
    NEXT:;
    }
  }
}
Problem p01359 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  while (true) {
    int N, Q;
    cin >> N >> Q;

    if (N == 0 && Q == 0) {
      break;
    }

    vector<string> names(N);
    vector<int> based(N);
    vector<int> year(N);

    for (int i = 0; i < N; i++) {
      cin >> names[i] >> based[i] >> year[i];
    }

    for (int i = 0; i < Q; i++) {
      int query;
      cin >> query;

      int ans_year = -1;
      string ans_name;

      for (int j = 0; j < N; j++) {
        if (year[j] < query) {
          continue;
        }

        int temp = based[j] - (year[j] - query);

        if (temp < 1) {
          continue;
        } else {
          ans_name = names[j];
          ans_year = temp;
          break;
        }
      }

      if (ans_year == -1) {
        cout << "Unknown" << endl;
      } else {
        cout << ans_name << " " << ans_year << endl;
      }
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  while (true) {
    int N, Q;
    cin >> N >> Q;

    if (N == 0 && Q == 0) {
      break;
    }

    vector<string> names(N);
    vector<int> based(N);
    vector<int> year(N);

    for (int i = 0; i < N; i++) {
      cin >> names[i] >> based[i] >> year[i];
    }

    for (int i = 0; i < Q; i++) {
      int query;
      cin >> query;

      string ans_str;
      int ans_year = -1;

      if (query <= year[0] - based[0] || query > year[N - 1]) {
        goto End;
      }

      for (int j = 0; j < N; j++) {
        if (query > year[j]) {
          continue;
        }

        for (int k = 0; k < based[j]; k++) {
          if (year[j] - k == query) {
            ans_str = names[j];
            ans_year = based[j] - k;
            goto End;
          }
        }
      }
    End:
      if (ans_year == -1) {
        cout << "Unknown" << endl;
      } else {
        cout << ans_str << " " << ans_year << endl;
      }
    }
  }

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

#include <iostream>
#include <string>
using namespace std;
string S[100000], U;
int n, a, b, c, d, p[100000][2];
int main() {
  while (true) {
    cin >> a >> b;
    if (a == 0 && b == 0) {
      break;
    }
    for (int i = 0; i < a; i++) {
      n = 0;
      cin >> U >> c >> d;
      S[i] = U;
      p[i][0] = d - c + 1;
      p[i][1] = d;
    }
    for (int i = 0; i < b; i++) {
      cin >> c;
      for (int j = 0; j < a; j++) {
        if (c >= p[j][0] && c <= p[j][1]) {
          cout << S[j] << ' ' << c - p[j][0] + 1 << endl;
          goto E;
        }
      }
      cout << "Unknown" << endl;
    E:;
    }
  }
}

Error: WA

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
string S[100], U;
int n, a, b, c, d, p[100][2];
char T[11] = "0123456789";
int main() {
  while (true) {
    cin >> a >> b;
    if (a == 0 && b == 0) {
      break;
    }
    for (int i = 0; i < a; i++) {
      n = 0;
      cin >> U >> c >> d;
      S[i] = U;
      p[i][0] = d - c + 1;
      p[i][1] = d - 1;
    }
    for (int i = 0; i < b; i++) {
      cin >> c;
      for (int j = 0; j < a; j++) {
        if (c >= p[j][0] && c <= p[j][1]) {
          cout << S[j] << ' ' << c - p[j][0] + 1 << endl;
          goto E;
        }
      }
      cout << "Unknown" << endl;
    E:;
    }
  }
}
Problem p01359 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

class era {
public:
  string name;
  int base, west;

  era(string n, int b, int w) {
    name = n;
    base = b;
    west = w;
  }

  bool operator<(const era &e) const { return (west < e.west); }
};

int main() {
  int Q, N, n, b, w;
  string nm;
  // ifstream cin("A.txt");

  while (cin >> Q >> N, Q || N) {
    vector<era> data;
    while (Q--) {
      cin >> nm >> b >> w;
      data.push_back(era(nm, b, w));
    }
    sort(data.begin(), data.end());

    while (N--) {
      cin >> n;
      string anss;
      int ansn;
      bool ok = false;
      for (int i = 0; i < data.size(); i++) {
        if (n - data[i].west + data[i].base > 0 && n - data[i].west <= 0) {
          ansn = n - data[i].west + data[i].base;
          anss = data[i].name;
          ok = true;
          break;
        }
      }

      if (ok) {
        cout << anss << " " << ansn << endl;
      } else {
        cout << "Unknown" << endl;
      }
    }
  }
}

Error: MLE

Fixed submission:

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

class era {
public:
  string name;
  int base, west;

  era(string n, int b, int w) {
    name = n;
    base = b;
    west = w;
  }

  bool operator<(const era &e) const { return (west < e.west); }
};

int main() {
  int Q, N, n, b, w;
  string nm;
  ifstream fin("A.txt");

  while (fin >> Q >> N, Q || N) {
    vector<era> data;
    while (Q--) {
      fin >> nm >> b >> w;
      data.push_back(era(nm, b, w));
    }
    sort(data.begin(), data.end());

    while (N--) {
      fin >> n;
      string anss;
      int ansn;
      bool ok = false;
      for (int i = 0; i < data.size(); i++) {
        if (n - data[i].west + data[i].base > 0 && n - data[i].west <= 0) {
          ansn = n - data[i].west + data[i].base;
          anss = data[i].name;
          ok = true;
          break;
        }
      }

      if (ok) {
        cout << anss << " " << ansn << endl;
      } else {
        cout << "Unknown" << endl;
      }
    }
  }
}
Problem p01359 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>

using namespace std;

#define NMAX 1000

struct S {
  int e, w;
  string n;
};

int main(void) {

  int N, Q;
  int q;
  S year[NMAX];

  while (1) {
    cin >> N >> Q;
    if (N == 0 && Q == 0)
      break;
    for (int i = 0; i < N; i++) {
      cin >> year[i].n >> year[i].e >> year[i].w;
    }
    for (int i = 0; i < Q; i++) {
      cin >> q;
      for (int i = 0; i < N; i++) {
        if (q >= year[i].w - year[i].e + 1 && q <= year[i].w) {
          cout << year[i].n << " " << q - (year[i].w - year[i].e) << endl;
          break;
        }
        if (i == N - 1)
          cout << "Unknown" << endl;
      }
    }
  }

  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

#define MAX 10000000

int main() {

  string data[MAX + 1];
  int yeda[MAX + 1];
  string en;
  int N, Q, eby, wy;
  int qu;
  string tm;

  while (1) {
    cin >> N >> Q;
    if (N == 0 && Q == 0)
      break;
    for (int i = 1; i <= MAX; i++) {
      data[i] = "Unkown";
      yeda[i] = -1;
    }
    for (int i = 0; i < N; i++) {
      cin >> en >> eby >> wy;
      for (int i = 0; i < 10; i++) {
        data[wy - eby + 1 + i] = en;
        yeda[wy - eby + 1 + i] = i + 1;
      }
    }
    for (int i = 0; i < Q; i++) {
      cin >> qu;
      if (data[qu] != "Unkown")
        cout << data[qu] << " " << yeda[qu] << endl;
      else
        cout << "Unkown" << endl;
    }
  }

  return 0;
}