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

#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;

#define LEN 100005

typedef struct pp {
  char name[100];
  int t;
} P;

P Q[LEN];
int head;
int tail;
int n;
// bool isEmpty()
// {
//     return head == tail;
// }
// bool isFull()
// {
//     return head == (tail + 1) % LEN;
// }
void enqueue(P x) {
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}
P dequeue() {
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;
}

int main() {
  int elaps = 0;
  int c, q;
  P u;
  scanf("%d %d", &n, &q);

  for (int i = 1; i <= n; i++) {
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }

  head = 1;
  tail = n + 1;
  while (head != tail) {
    u = dequeue();
    c = std::min(q, u.t);
    u.t -= c;
    elaps += c;
    if (u.t > 0)
      enqueue(u);
    else {
      printf("%s %d\\n", u.name, elaps);
    }
  }
  return 0;
}


Error: -11

Fixed submission:


#include <iostream>
#include <map>
#include <stdio.h>
#include <string>
using namespace std;

#define LEN 100005

typedef struct pp {
  char name[100];
  int t;
} P;

P Q[LEN];
int head = 0;
int tail = 0;
int n;
bool isEmpty() { return head == tail; }
bool isFull() { return head == (tail + 1) % LEN; }
void enqueue(P x) {
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}
P dequeue() {
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;
}

int main() {
  int n, q;
  int elaps = 0;
  int c;
  P u;
  cin >> n >> q;

  for (int i = 0; i < n; i++) {
    scanf("%s", Q[i].name);
    scanf("%d", Q[i].t);
  }

  head = 1;
  tail = n + 1;
  while (head != tail) {
    u = dequeue();
    c = std::min(q, u.t);
    u.t -= c;
    elaps += c;
    if (u.t > 0)
      enqueue(u);
    else {
      printf("%s %d\\n", u.name, elaps);
    }
  }
  return 0;
}
Problem p02264 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
#define len 100005
struct task {
  char name[100];
  int time;
};
int head = 0, tail = 0;
void enqueue(task add, task *q) {
  q[tail] = add;
  tail = (tail + 1) % len;
}

task dequeue(task *q) {
  task temp = q[head];
  head = (head + 1) % len;
  return temp;
}
task tasks[len];
int main() {
  int t0, n;
  cin >> n >> t0;
  int t = 0;
  for (int i = 0; i < n; i++) {
    cin >> tasks[i].name >> tasks[i].time;
    tail++;
  }
  while (head != tail || (head == 0 && tail == 0)) {
    if (tasks[head].time <= t0) {
      t += tasks[head].time;
      tasks[head].time = 0;
      cout << tasks[head].name << " " << t << endl;
      dequeue(tasks);
    } else {
      t += t0;
      tasks[head].time -= t0;
      enqueue(tasks[head], tasks);
      dequeue(tasks);
    }
  }
  int x = 1;
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;
#define len 100005;
struct task {
  char name[100];
  int time;
};
int head = 0, tail = 0;
void enqueue(task add, task *q) {
  q[tail] = add;
  tail = (tail + 1) % len;
}

task dequeue(task *q) {
  task temp = q[head];
  head = (head + 1) % len;
  return temp;
}

int main() {
  int t0, n;
  cin >> n >> t0;
  task tasks[100];
  int t = 0;
  for (int i = 0; i < n; i++) {
    cin >> tasks[i].name >> tasks[i].time;
    tail++;
  }
  while (head != tail || (head == 0 && tail == 0)) {
    if (tasks[head].time <= t0) {
      t += tasks[head].time;
      tasks[head].time = 0;
      cout << tasks[head].name << " " << t << endl;
      dequeue(tasks);
    } else {
      t += t0;
      tasks[head].time -= t0;
      enqueue(tasks[head], tasks);
      dequeue(tasks);
    }
  }
  return 0;
}
Problem p02264 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
#include <string.h>
#define LEN 100005

/* プロセスを表す構造体 */
typedef struct pp {
  char name[100];
  int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x) {
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}

P dequeue() {
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;
}

int min(int a, int b) { return a < b ? a : b; } /* 最小値を返す */

int main() {
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  /* 全てのプロセスをキューに順番に追加する */
  for (i = 1; i <= n; i++) {
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 1;
  tail = n + 1;

  /* シミュレーション */
  while (head != tail) {
    u = dequeue();
    c = min(q, u.t); /* q または必要な時間 u.t だけ処理を行う */
    u.t -= c;        /* 残りの必要時間を計算 */
    elaps += c;      /* 経過時間を計算 */
    if (u.t > 0)
      enqueue(u); /* 処理が完了していなければキューに追加 */
    else
      printf("%s %d\\n", u.name, elaps);
  }

  return 0;
}


Error: -11

Fixed submission:

#include <stdio.h>
#include <string.h>
#define LEN 100005

/* プロセスを表す構造体 */
typedef struct pp {
  char name[100];
  int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x) {
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}

P dequeue() {
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;
}

int min(int a, int b) { return a < b ? a : b; } /* 最小値を返す */

int main() {
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  /* 全てのプロセスをキューに順番に追加する */
  for (i = 1; i <= n; i++) {
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 1;
  tail = n + 1;

  /* シミュレーション */
  while (head != tail) {
    u = dequeue();
    c = min(q, u.t); /* q または必要な時間 u.t だけ処理を行う */
    u.t -= c;        /* 残りの必要時間を計算 */
    elaps += c;      /* 経過時間を計算 */
    if (u.t > 0)
      enqueue(u); /* 処理が完了していなければキューに追加 */
    else
      printf("%s %s", u.name, elaps);
  }

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

#include <cstdio>
#include <cstdlib>
#include <queue>
#include <stack>

#define MAX 100005

using namespace std;

struct Ques {
  char name[100];
  int time;
};

Ques Q[MAX];

// ??¬???

int main() {

  int n, q, i, k, timer, head, tail;

  scanf("%d %d", &n, &q);

  head = 0;
  tail = n;

  Ques buffer;

  int last_time = 0;

  for (i = 0; i < n; i++) {

    scanf("%s", buffer.name);

    scanf("%d", &buffer.time);

    Q[i] = buffer;
  }

  while (head != tail) {

    timer = min(q, Q[head].time);
    last_time += timer;

    Q[head].time -= timer;

    if (Q[head].time > 0) {

      Q[tail] = Q[head];

      tail++;
      if (tail > MAX)
        tail = 0;
      head++;
      if (head > MAX)
        head = 0;

    } else {

      printf("%s %d\\n", Q[head].name, last_time);

      head++;
      if (head > MAX)
        head = 0;
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

struct Ques {
  char name[100];
  int time;
};

Ques Q[100005];

//??????????????????????????£??????

void begin_to_last(Ques Q[], int N) {

  Ques buffer;

  buffer = Q[0];

  for (int i = 0; i < N - 1; i++) {

    Q[i] = Q[i + 1];
  }

  Q[N] = buffer;
}

// Q[k]?????????????????£??????

void k_to_last(Ques Q[], int N, int k) {

  Ques buffer;

  buffer = Q[k];

  for (int i = k; i < N - 1; i++) {

    Q[i] = Q[i + 1];
  }

  Q[N] = buffer;
}

// ??¬???

int main() {

  int n, q, i, k, timer;

  scanf("%d %d", &n, &q);

  Ques buffer;

  int last_time = 0;

  for (i = 0; i < n; i++) {

    scanf("%s", buffer.name);

    scanf("%d", &buffer.time);

    Q[i] = buffer;
  }

  k = n;

  while (k > 0) {

    for (i = 0; i < k; i++) {

      timer = min(q, Q[i].time);
      last_time += timer;

      Q[i].time -= timer;

      if (Q[i].time == 0) {

        printf("%s %d\\n", Q[i].name, last_time);

        k_to_last(Q, n, i);

        k--;
        i--;
      }
    }
  }

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

#include <cstdio>

#define MAX_N 100000
#define MAX_NAME 10

typedef struct Queue {
  char name[MAX_NAME];
  int time;
  struct Queue *qnext;
  struct Queue *qprev;
} Queue;

int main() {
  int n, q;
  int sum = 0;
  Queue *pPoint;
  int sTime = 0;

  scanf("%d %d", &n, &q);

  Queue *queue = new Queue[n];
  if (NULL == queue) {
    return -1;
  }

  // 　Queueの初期化処理
  for (int i = 0; i < n; i++) {
    if (i == 0) {
      if (n > 1) {
        queue[i].qprev = queue + (n - 1);
        queue[i].qnext = queue + (i + 1);
      } else {
        queue[i].qprev = NULL;
        queue[i].qnext = NULL;
      }
    } else if (i == (n - 1)) {
      queue[i].qnext = queue;
      queue[i].qprev = queue + (i - 1);
    } else {
      queue[i].qprev = queue + (i - 1);
      queue[i].qnext = queue + (i + 1);
    }
    scanf("%s", &(queue[i].name));
    scanf("%d", &(queue[i].time));
    sum += queue[i].time;
  }

  Queue *tmpQ;
  pPoint = queue;
  while (sum > 0) {
    if (pPoint->time <= q) {
      sTime += pPoint->time;
      printf("%s %d\\n", pPoint->name, sTime);
      sum -= pPoint->time;
      // prev, next を外す
      tmpQ = pPoint;
      if (tmpQ->qnext != NULL) {
        pPoint = tmpQ->qnext;
        pPoint->qprev = tmpQ->qprev;
        pPoint->qprev->qnext = pPoint;
      }
    } else {
      pPoint->time -= q;
      sTime += q;
      sum -= q;
      if (pPoint->qnext != NULL) {
        pPoint = pPoint->qnext;
      }
    }
  }
  delete[] queue;
  return 0;
}


Error: 0

Fixed submission:

#include <cstdio>

#define MAX_N 100000
#define MAX_NAME 10

typedef struct Queue {
  char name[MAX_NAME];
  int time;
  struct Queue *qnext;
  struct Queue *qprev;
} Queue;

int main() {
  int n, q;
  int sum = 0;
  Queue *pPoint;
  int sTime = 0;

  scanf("%d %d", &n, &q);

  Queue *queue = new Queue[n];
  if (NULL == queue) {
    return -1;
  }

  // 　Queueの初期化処理
  for (int i = 0; i < n; i++) {
    if (i == 0) {
      queue[i].qprev = queue + (n - 1);
      queue[i].qnext = queue + (i + 1);
    } else if (i == (n - 1)) {
      queue[i].qnext = queue;
      queue[i].qprev = queue + (i - 1);
    } else {
      queue[i].qprev = queue + (i - 1);
      queue[i].qnext = queue + (i + 1);
    }
    scanf("%s", &(queue[i].name));
    scanf("%d", &(queue[i].time));
    sum += queue[i].time;
  }

  Queue *tmpQ;
  pPoint = queue;
  while (sum > 0) {
    if (pPoint->time <= q) {
      sTime += pPoint->time;
      printf("%s %d\\n", pPoint->name, sTime);
      sum -= pPoint->time;
      // prev, next を外す
      tmpQ = pPoint;
      pPoint = tmpQ->qnext;
      pPoint->qprev = tmpQ->qprev;
      pPoint->qprev->qnext = pPoint;
    } else {
      pPoint->time -= q;
      sTime += q;
      sum -= q;
      pPoint = pPoint->qnext;
    }
  }
  delete[] queue;
  return 0;
}
Problem p02264 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <queue>
#include <stdio.h>
#include <string>
#include <tuple>

using namespace std;

int main() {
  int n, q;
  int time = 0;
  scanf("%d %d", &n, &q);

  string temps;
  int tempv;
  queue<tuple<string, int>> processes;
  for (int i = 0; i < n; ++i) {
    cin >> temps >> tempv;
    tuple<string, int> tempt = make_tuple(temps, tempv);
    processes.push(tempt);
  }

  int i = 0;
  while (n != 0) {

    tuple<string, int> &process = processes.front();
    int &temp = get<1>(process);

    if (temp <= q) {
      string &name = get<0>(process);
      time += temp;
      cout << name << " " << time << endl;
      processes.pop();
      n -= 1;
    } else {
      time += q;
      temp -= q;
      processes.push(make_tuple(get<0>(process), temp));
      processes.pop();
    }
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

int main() {
  int n, q;
  int time = 0;
  scanf("%d %d", &n, &q);

  string temps;
  int tempv;
  vector<tuple<string, int>> processes;
  for (int i = 0; i < n; ++i) {
    cin >> temps >> tempv;
    tuple<string, int> tempt = make_tuple(temps, tempv);
    processes.push_back(tempt);
  }

  int i = 0;
  int count = n;
  while (count != 0) {
    if (i == n) {
      i = 0;
    }

    tuple<string, int> &process = processes[i];
    int &temp = get<1>(process);

    if (temp == -1) {
      i += 1;
      continue;
    }

    if (temp <= q) {
      string &name = get<0>(process);
      time += temp;
      cout << name << " " << time << endl;
      temp = -1;
      count -= 1;
    } else {
      time += q;
      temp -= q;
      i += 1;
    }
  }

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

#include <iostream>
#include <queue>
#include <string>

using namespace std;

int main() {
  int n;
  int q;
  int time_cnt = 0;
  std::queue<string> name;
  std::queue<int> time;
  std::string name1[100000];
  int time1[100000];
  std::string k_name;
  int k_time;

  std::cin >> n >> q;

  for (int i = 0; i < n; i++) {
    std::cin >> name1[i] >> time1[i];
    name.push(name1[i]);
    time.push(time1[i]);
  }

  while (name.size() != 0) {
    if (time.front() <= q) {
      time_cnt += time.front();
      std::cout << name.front() << " " << time_cnt << '\\n';
      name.pop();
      time.pop();
    } else {
      time.front() -= q;
      time_cnt += q;
      k_name = name.front();
      k_time = time.front();
      name.pop();
      time.pop();
      name.push(k_name);
      time.push(k_time);
    }
  }
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
#include <queue>
#include <string>

using namespace std;

int main() {
  int n;
  int q;
  int time_cnt = 0;
  std::queue<string> name;
  std::queue<int> time;
  std::string name1[10000];
  int time1[10000];
  std::string k_name;
  int k_time;

  std::cin >> n >> q;

  for (int i = 0; i < n; i++) {
    std::cin >> name1[i] >> time1[i];
    name.push(name1[i]);
    time.push(time1[i]);
  }

  while (name.size() != 0) {
    if (time.front() <= q) {
      time_cnt += time.front();
      std::cout << name.front() << " " << time_cnt << '\\n';
      name.pop();
      time.pop();
    } else {
      time.front() -= q;
      time_cnt += q;
      k_name = name.front();
      k_time = time.front();
      name.pop();
      time.pop();
      name.push(k_name);
      time.push(k_time);
    }
  }
  return 0;
}
Problem p02264 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

struct Process {
  string name;
  int time;
};

struct Queue {
  const int length = 100005;
  int head;
  int tail;
  Process processes[100005];

  void enqueue(Process x) {
    processes[tail] = x;
    tail = (tail + 1) % length;
  }

  Process dequeue() {
    Process x = processes[head];
    head = (head + 1) % length;
    return x;
  }
};

int main() {
  int elaps = 0, c;
  int n, q;
  Process u;
  cin >> n >> q;
  Queue queue;
  for (int i = 1; i <= n; ++i) {
    cin >> queue.processes[i].name;
    cin >> queue.processes[i].time;
  }
  queue.head = 1;
  queue.tail = n + 1;

  while (queue.head != queue.tail) {
    u = queue.dequeue();
    c = min(q, u.time);
    u.time -= c;
    elaps += c;
    if (u.time > 0) {
      queue.enqueue(u);
    } else {
      cout << u.name << ' ' << elaps << endl;
    }
  }

  return 0;
}


Error: 0

Fixed submission:

#include <cstdio>
#include <cstring>
#include <string>

using namespace std;

struct Process {
public:
  char n[10];
  int t;
};

class Queue {
public:
  Process data[100005];
  int head;
  int tail;
  int max = 100005;

  void enqueue(Process p) {
    data[tail] = p;

    if (tail + 1 >= max) {
      tail = 0;
    } else {
      tail++;
    }
  }

  Process dequeue() {
    Process p = data[head];

    if (head + 1 >= max) {
      head = 0;
    } else {
      head++;
    }

    return p;
  }
};

int main() {
  int n;
  scanf("%d", &n);

  int q;
  scanf("%d", &q);

  int elaps = 0;

  Queue queue;
  for (int i = 0; i < n; i++) {
    Process p;

    char name[10];
    scanf("%s", name);
    int t;
    scanf("%d", &t);

    strcpy(p.n, name);
    p.t = t;

    queue.enqueue(p);
  }
  queue.head = 0;
  queue.tail = n;

  while (queue.head != queue.tail) {
    Process u = queue.dequeue();
    int c = min(q, u.t);
    u.t -= c;
    elaps += c;
    if (u.t > 0) {
      queue.enqueue(u);
    } else {
      printf("%s %d\\n", u.n, elaps);
    }
  }

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

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

typedef struct Process {
  string name;
  int time;
  Process(string n, int t) {
    name = n;
    time = t;
  };
  Process() {
    name = " ";
    time = 0;
  };
};

template <class Type> class Queue {
private:
  int head = 0, tail = 0;
  Type queue[100009];

public:
  Queue(){};

  void push(const Type &p) {
    queue[tail] = p;
    tail++;
    tail = (tail + 1) % 100009;
  }

  Type pop() {
    Type x = queue[head];
    head++;
    head = (head + 1) % 100009;
    return x;
  }

  Type front() { return queue[head]; }
};

int main() {
  int n, q, allTime = 0;
  cin >> n >> q;
  Process p;
  Queue<Process> Q;
  for (int i = 0; i < n; i++) {
    cin >> p.name;
    cin >> p.time;
    Q.push(p);
  }
  while (n > 0) {
    if (Q.front().time <= q) {
      allTime += Q.front().time;
      cout << Q.front().name << " " << allTime << endl;
      Q.pop();
      n--;
    } else {
      allTime += q;
      Q.push(Process(Q.front().name, Q.front().time - q));
      Q.pop();
    }
  }
}

Error: 0

Fixed submission:

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

typedef struct Process {
  string name;
  int time;
  Process(string n, int t) {
    name = n;
    time = t;
  };
  Process() {
    name = " ";
    time = 0;
  };
};

template <class Type> class Queue {
private:
  int head = 0, tail = 0;
  Type queue[100009];

public:
  Queue(){};

  void push(const Type &p) {
    queue[tail] = p;
    tail++;
    tail % 100009;
  }

  Type pop() {
    Type x = queue[head];
    head++;
    head % 100009;
    return x;
  }

  Type front() { return queue[head]; }
};

int main() {
  int n, q, allTime = 0;
  cin >> n >> q;
  Process p;
  Queue<Process> Q;
  for (int i = 0; i < n; i++) {
    cin >> p.name;
    cin >> p.time;
    Q.push(p);
  }
  while (n > 0) {
    if (Q.front().time <= q) {
      allTime += Q.front().time;
      cout << Q.front().name << " " << allTime << endl;
      Q.pop();
      n--;
    } else {
      allTime += q;
      Q.push(Process(Q.front().name, Q.front().time - q));
      Q.pop();
    }
  }
}
Problem p02264 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <map>
#include <queue>
#include <string>
using namespace std;

queue<pair<string, int>> que;

void solve(int q) {
  int timer = 0;
  while (!que.empty()) {
    // pair<string, int>* tp;
    // tp =  &que.front();
    // int* tmp = &tp->second;

    if (que.front().second > 0) {
      if (que.front().second <= q) {
        timer += que.front().second;
        cout << que.front().first << " " << timer << endl;
        ;
      } else {
        timer += q;
        que.front().second -= q;
        que.push(que.front());
      }
      que.pop();
    }
  }
  return;
}

int main() {
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    string name;
    int tmp;
    cin >> name >> tmp;
    que.push(make_pair(name, tmp));
  }
  solve(q);
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <map>
#include <queue>
#include <string>
using namespace std;

queue<pair<string, int>> que;

void solve(int q) {
  int timer = 0;
  while (que.size() > 0) {
    pair<string, int> *tp;
    tp = &que.front();
    int *tmp = &tp->second;
    que.pop();

    if (*tmp > 0) {
      if (*tmp <= q) {
        timer += *tmp;
        cout << tp->first << " " << timer << endl;
        ;
      } else {
        timer += q;
        *tmp -= q;
        que.push(*tp);
      }
    }
  }
  return;
}

int main() {
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    string name;
    int tmp;
    cin >> name >> tmp;
    que.push(make_pair(name, tmp));
  }
  solve(q);
  return 0;
}
Problem p02264 (C++) — buggy submission, verdict: Runtime Error

#include <cstdlib>
#include <iostream>
#include <string>

#define N 100000
using namespace std;

class Queue {
private:
  int num[N];
  int head;
  int tail;

public:
  Queue() {
    head = 0;
    tail = 0;
  }

  // add to head position
  void push(int x) {
    num[tail] = x;
    tail++;
  }
  // delete head position
  void pop(void) { head++; }
  // return now of stck
  int front(void) { return num[head]; }
};

int main() {

  Queue que;
  //
  bool finish[N];
  int n, q, tim = 0;
  string name[N];
  int time[N], i = 0;
  int passtime = 0;

  // load n and q
  cin >> n >> q;

  // load name and time
  for (i = 0; i < n; i++) {
    cin >> name[i] >> tim;
    que.push(tim);
    time[i] = 0;
  }

  // format finish[]
  for (int k = 0; k < n; k++)
    finish[k] = false;

  while (1) {
    int s;
    bool end = true;
    for (int k = 0; k < n; k++) {
      if (!finish[k]) {
        end = false;
        break;
      }
    }
    if (end)
      break;
    else
      end = true;

    if (i == n)
      i = 0;

    if (finish[i]) {
      i++;
      continue;
    }

    s = que.front();
    if (s - q > 0) {
      que.push(s - q);
      que.pop();
      passtime += q;
      time[i] = passtime;

    } else {
      que.pop();
      passtime += s;
      time[i] = passtime;
      finish[i] = true;
      cout << name[i] << " " << time[i] << endl;
    }
    i++;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <cstdlib>
#include <iostream>
#include <string>

#define N 10000
using namespace std;

class Queue {
private:
  int num[N];
  int head;
  int tail;

public:
  Queue() {
    head = 0;
    tail = 0;
  }

  // add to head position
  void push(int x) {
    num[tail] = x;
    tail++;
  }
  // delete head position
  void pop(void) { head++; }
  // return now of stck
  int front(void) { return num[head]; }
};

int main() {

  Queue que;
  //
  bool finish[N];
  int n, q, tim = 0;
  string name[N];
  int time[N], i = 0;
  int passtime = 0;

  // load n and q
  cin >> n >> q;

  // load name and time
  for (i = 0; i < n; i++) {
    cin >> name[i] >> tim;
    que.push(tim);
    time[i] = 0;
  }

  // format finish[]
  for (int k = 0; k < n; k++)
    finish[k] = false;

  while (1) {
    int s;
    bool end = true;
    for (int k = 0; k < n; k++) {
      if (!finish[k]) {
        end = false;
        break;
      }
    }
    if (end)
      break;
    else
      end = true;

    if (i == n)
      i = 0;

    if (finish[i]) {
      i++;
      continue;
    }

    s = que.front();
    if (s - q > 0) {
      que.push(s - q);
      que.pop();
      passtime += q;
      time[i] = passtime;

    } else {
      que.pop();
      passtime += s;
      time[i] = passtime;
      finish[i] = true;
      cout << name[i] << " " << time[i] << endl;
    }
    i++;
  }

  return 0;
}