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

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

#define abs(N) ((N > 0) ? N : -1 * N)
#define lt(A, B) ((A > B) ? B : A)
#define gt(A, B) ((A < B) ? B : A)
#define print(S) (cout << S)
#define println(S) (cout << S << endl)

template <typename T> class queue {
public:
  const static int LEN = 1000000;
  queue<T>() { head = tail = 0; }

  void empty() { head = tail = 0; }

  bool isEmpty() { return (head == tail); }

  bool isFull() { return ((tail + 1) % LEN == head); }

  T dequeue() {
    if (isEmpty()) {
      throw exception();
    }
    if (head == LEN - 1) {
      head = 0;
      return body[LEN - 1];
    }
    return body[head++];
  }

  void enqueue(T el) {
    if (isFull()) {
      throw exception();
    }
    if (tail == LEN - 1) {
      tail = 0;
      body[LEN - 1] = el;
    } else {
      body[tail++] = el;
    }
  }

  T top() {
    if (isEmpty()) {
      throw exception();
    }
    return body[head];
  }

private:
  T body[LEN];
  int head, tail;
};

typedef struct {
  string name;
  int time;
} process;

int main() {
  queue<process> que;
  int n, q;
  cin >> n >> q;

  for (int i = 0; i < n; ++i) {
    process p;
    cin >> p.name >> p.time;
    que.enqueue(p);
  }
  int t = 0;
  while (!que.isEmpty()) {
    process p = que.dequeue();
    if (p.time > q) {
      p.time -= q;
      que.enqueue(p);
      t += q;
    } else {
      t += p.time;
      cout << p.name << " " << t << endl;
      ;
    }
  }

  return 0;
}


Error: 0

Fixed submission:

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

#define abs(N) ((N > 0) ? N : -1 * N)
#define lt(A, B) ((A > B) ? B : A)
#define gt(A, B) ((A < B) ? B : A)
#define print(S) (cout << S)
#define println(S) (cout << S << endl)

template <typename T> class queue {
public:
  const static int LEN = 10000;
  queue<T>() { head = tail = 0; }

  void empty() { head = tail = 0; }

  bool isEmpty() { return (head == tail); }

  bool isFull() { return ((tail + 1) % LEN == head); }

  T dequeue() {
    if (isEmpty()) {
      throw exception();
    }
    if (head == LEN - 1) {
      head = 0;
      return body[LEN - 1];
    }
    return body[head++];
  }

  void enqueue(T el) {
    if (isFull()) {
      throw exception();
    }
    if (tail == LEN - 1) {
      tail = 0;
      body[LEN - 1] = el;
    } else {
      body[tail++] = el;
    }
  }

  T top() {
    if (isEmpty()) {
      throw exception();
    }
    return body[head];
  }

private:
  T body[LEN];
  int head, tail;
};

typedef struct {
  string name;
  int time;
} process;

int main() {
  queue<process> que;
  int n, q;
  cin >> n >> q;

  for (int i = 0; i < n; ++i) {
    process p;
    cin >> p.name >> p.time;
    que.enqueue(p);
  }
  int t = 0;
  while (!que.isEmpty()) {
    process p = que.dequeue();
    if (p.time > q) {
      p.time -= q;
      que.enqueue(p);
      t += q;
    } else {
      t += p.time;
      cout << p.name << " " << t << endl;
      ;
    }
  }

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

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

struct queue {
  string name;
  int time;
};

int tail, head;
queue Q[1000000];

void enqueue(queue x);
queue dequeue();

int main() {
  int n, q, t = 0, sum = 0;
  string str;
  cin >> n >> q;
  tail = n;
  head = 0;
  for (int i = 0; i < n; i++)
    cin >> Q[i].name >> Q[i].time;

  while (sum != n) {
    if (Q[head].time <= q)
      t += Q[head].time;
    else
      t += q;
    Q[head].time -= q;
    if (Q[head].time <= 0) {
      cout << Q[head].name << ' ' << t << endl;
      head++;
      sum++;
    } else
      enqueue(dequeue());
  }
  return 0;
}

void enqueue(queue x) { Q[tail++] = x; }

queue dequeue() { return Q[head++]; }

Error: MLE

Fixed submission:

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

struct queue {
  string name;
  int time;
};

int tail, head;
queue Q[10000000];

void enqueue(queue x);
queue dequeue();

int main() {
  int n, q, t = 0, sum = 0;
  string str;
  cin >> n >> q;
  tail = n;
  head = 0;
  for (int i = 0; i < n; i++)
    cin >> Q[i].name >> Q[i].time;

  while (sum != n) {
    if (Q[head].time <= q)
      t += Q[head].time;
    else
      t += q;
    Q[head].time -= q;
    if (Q[head].time <= 0) {
      cout << Q[head].name << ' ' << t << endl;
      head++;
      sum++;
    } else
      enqueue(dequeue());
  }
  return 0;
}

void enqueue(queue x) { Q[tail++] = x; }

queue dequeue() { return Q[head++]; }
Problem p02264 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef pair<string, int> P;
P a[100005];
int n, m;
int sti;
int en;
int N;
P mpop();
void mpush(P);
int main() {
  cin >> n >> m;
  N = n;
  en = n - 1;
  for (int i = 0; i < n; i++) {
    cin >> a[i].first >> a[i].second;
  }
  int co = 0;
  while (n != 0) {
    P x = mpop();
    n--;
    if (x.second <= m) {
      co += x.second;
      cout << x.first << " " << co << endl;
    } else {
      co += m;
      x.second -= m;
      mpush(x);
      n++;
    }
  }
  return 0;
}
P mpop() {
  P re;
  // cout << "pop" << endl;
  while (a[sti].second == -1) {
    sti++;
    if (sti >= N)
      sti = 0;
  }
  re = a[sti];
  a[sti].second = -1;
  while (a[sti].second == -1 && n != 1) {
    sti++;
    if (sti >= N)
      sti = 0;
  }
  return re;
}
void mpush(P p) {
  // cout << "push" << endl;
  en++;
  if (en == N)
    en = 0;
  a[en] = p;
  while (a[sti].second == -1) {
    sti++;
    if (sti >= N)
      sti = 0;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  pair<string, int> a[100005], pop;
  for (int i = 0; i < n; i++) {
    cin >> a[i].first >> a[i].second;
  }
  int co = 0;
  while (n != 0) {
    if (a[0].second <= m) {
      co += a[0].second;
      cout << a[0].first << " " << co << endl;
      for (int i = 0; i < n - 1; i++) {
        a[i] = a[i + 1];
      }
      n--;
    } else {
      co += m;
      a[0].second -= m;
      pop = a[0];
      for (int i = 0; i < n - 1; i++) {
        a[i] = a[i + 1];
      }
      a[n - 1] = pop;
    }
  }
  return 0;
}
Problem p02264 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <iostream>
#include <sstream>

const int QUEUE_SIZE = 100000;

struct Process {
  int time;
  int remain;
  std::string name;
};

int main() {
  int n = 0;
  int q = 0;

  std::cin >> n;
  std::cin >> q;

  struct Process queue[QUEUE_SIZE];
  int count = 0;

  int front = 0;
  int rear = 0;

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

    rear++;
  }

  int time = 0;

  while (front != rear) {
    struct Process p = queue[front];
    front++;

    front = front % QUEUE_SIZE;

    p.time -= q;

    if (p.time > 0) {
      time += q;

      queue[rear] = p;
      rear++;

      rear = rear % QUEUE_SIZE;
    } else {
      time += q + p.time;

      std::cout << p.name << " " << time << std::endl;
      ;
    }
  }

  return 0;
}

Error: -11

Fixed submission:

#include <cmath>
#include <cstdlib>
#include <iostream>
#include <sstream>

const int QUEUE_SIZE = 100000;

struct Process {
  int time;
  int remain;
  std::string name;
};

int main() {
  int n = 0;
  int q = 0;

  std::cin >> n;
  std::cin >> q;

  struct Process *queue[QUEUE_SIZE];
  int count = 0;

  int front = 0;
  int rear = 0;

  for (int i = 0; i < n; i++) {
    struct Process *p = (struct Process *)malloc(sizeof(struct Process));

    std::cin >> p->name;
    std::cin >> p->time;

    queue[rear] = p;
    rear++;
  }

  int time = 0;

  while (front != rear) {
    struct Process *p = queue[front];
    front++;

    front = front % QUEUE_SIZE;

    p->time -= q;

    if (p->time > 0) {
      time += q;

      queue[rear] = p;
      rear++;

      rear = rear % QUEUE_SIZE;
    } else {
      time += q + p->time;

      std::cout << p->name << " " << time << std::endl;
      ;
    }
  }

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

#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
#define M 100000
typedef struct PT {
  char name[11];
  int time;
} PT;
PT a[M + 1];
int head = 0, tail = 0;
void Init() { head = tail = 0; }
bool IsFull() { return tail - head == -1 || tail - head == M; }
bool IsEmpty() { return head == tail; }
PT dequeue() {
  if (IsEmpty()) {
    cout << "EMPTY" << endl;
    exit(1);
  }
  if (head == M) {
    head = 0;
    return a[M];
  }
  ++head;
  return a[head - 1];
}
void enqueue(PT x) {
  if (IsFull()) {
    cout << "FULL" << endl;
    exit(1);
  }
  a[tail] = x;
  ++tail;
  if (tail == M + 1)
    tail = 0;
}
int main() {
  PT in;
  int i, n, q, time = 0;
  cin >> n >> q;
  for (i = 0; i < n; i++) {
    // cin>>in.name>>in.time;
    scanf("%s%d", in.name, &in.time);
    enqueue(in);
  }
  while (!IsEmpty()) {
    in = dequeue();
    if (in.time <= q) {
      time += in.time;
      // cout<<in.name<<' '<<time<<endl;
      printf("%s %d\\n", in.name, time);
    } else {
      time += q;
      in.time -= q;
      enqueue(in);
    }
  }
  return 0;
}

Error: -11

Fixed submission:

#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
#define M 100000
typedef struct PT {
  char name[11];
  int time;
} PT;
PT a[M + 1];
int head = 0, tail = 0;
void Init() { head = tail = 0; }
bool IsFull() { return tail - head == -1 || tail - head == M; }
bool IsEmpty() { return head == tail; }
PT dequeue() {
  if (IsEmpty()) {
    cout << "EMPTY" << endl;
    exit(1);
  }
  if (head == M) {
    head = 0;
    return a[M];
  }
  ++head;
  return a[head - 1];
}
void enqueue(PT x) {
  if (IsFull()) {
    cout << "FULL" << endl;
    exit(1);
  }
  a[tail] = x;
  ++tail;
  if (tail == M + 1)
    tail = 0;
}
int main() {
  PT in;
  int i, n, q, time = 0;
  cin >> n >> q;
  for (i = 0; i < n; i++) {
    // cin>>in.name>>in.time;
    scanf("%s%d", in.name, &in.time);
    enqueue(in);
  }
  while (!IsEmpty()) {
    in = dequeue();
    if (in.time <= q) {
      time += in.time;
      // cout<<in.name<<' '<<time<<endl;
      printf("%s %d\\n", in.time, time);
    } else {
      time += q;
      in.time -= q;
      enqueue(in);
    }
  }
  return 0;
}
Problem p02264 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define vvi vector<vector<int>>
#define All(X) X.begin(), X.end()
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

queue<pair<string, int>> Q;
int n;
int quantum;
int main() {
  int n;
  cin >> n >> quantum;
  REP(i, n) {
    string tmpstr;
    int tmptime;
    cin >> tmpstr >> tmptime;
    Q.push(make_pair(tmpstr, tmptime));
  }
  ll int nowtime = 0;
  while (!Q.empty()) {
    int tmp = Q.front().second;
    if (tmp <= quantum) {
      nowtime += tmp;
      cout << Q.front().first << " " << nowtime << endl;
      Q.pop();
    } else {
      nowtime += quantum;
      Q.push(make_pair(Q.front().first, tmp - quantum));
      Q.pop();
    }
  }
}

Error: -11

Fixed submission:

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

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

int main() {
  int n, i, q, sum = 0, last;
  P Q[LEN + 1];
  scanf("%d %d", &n, &q);

  for (i = 1; i <= n; i++) {
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  Q[n + 1].name[0] = '\\0';
  i = 1;
  last = n;
  while (1) {
    if (Q[i].name[0] == '\\0') {
      break;
    }
    if (Q[i].t > q) {
      sum += q;
      strcpy(Q[last + 1].name, Q[i].name);
      Q[last + 1].t = Q[i].t - q;
      Q[last + 2].name[0] = '\\0';
      last++;
    } else {
      sum += Q[i].t;
      printf("%s %d\\n", Q[i].name, sum);
    }
    i++;
  }
  return 0;
}
Problem p02264 (C++) — buggy submission, verdict: Runtime Error

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

typedef struct Process {
  char name[100];
  int time;
} P;

class myQueue {
public:
  myQueue(int n) {
    data = new P[n];
    head = 0;
    tail = 0;
    MAX = n;
  }
  ~myQueue() {
    // delete [] data;
  }
  void enqueue(P x) {
    data[tail] = x;
    if (tail + 1 == 100005)
      tail = 0;
    else
      tail++;
  }
  P dequeue() {
    P x = data[head];
    if (head + 1 == 100005)
      head = 0;
    else
      head++;
    return x;
  }
  void PrintQueue() {
    for (int i = 0; i < MAX; i++) {
      cout << data[i].name << " " << data[i].time << endl;
    }
  }
  bool isEmpty() { return head == tail; }

private:
  P *data;
  int head, tail;
  int MAX;
};

int main() {
  int n, q;
  cin >> n >> q;
  myQueue queue(100005);
  P p;
  for (int i = 0; i < n; i++) {
    cin >> p.name >> p.time;
    queue.enqueue(p);
    // queue.PrintQueue();
  }
  // cout << n << " " << q << endl;
  // queue.PrintQueue();

  int t = 0;
  while (!queue.isEmpty()) {
    p = queue.dequeue();
    if (p.time >= q) {
      t += q;
      p.time -= q;
    } else {
      t += p.time;
      p.time = 0;
    }

    if (p.time <= 0) {
      printf("%s %d\\n", p.name, t);
      // cout << p.name << " " << t << endl;
    } else {
      queue.enqueue(p);
    }
  }
  return 0;
}


Error: WA

Fixed submission:

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

typedef struct Process {
  char name[100];
  int time;
} P;

class myQueue {
public:
  myQueue(int n) {
    data = new P[n];
    head = 0;
    tail = 0;
    MAX = n;
  }
  ~myQueue() {
    // delete [] data;
  }
  void enqueue(P x) {
    data[tail] = x;
    tail++;
  }
  Process dequeue() {
    head++;
    return data[head - 1];
  }
  void PrintQueue() {
    for (int i = 0; i < MAX; i++) {
      cout << data[i].name << " " << data[i].time << endl;
    }
  }
  bool isEmpty() { return head == tail; }

private:
  P *data;
  int head, tail;
  int MAX;
};

int main() {
  int n, q;
  cin >> n >> q;
  myQueue queue(n);
  P p = {"", 0};
  for (int i = 0; i < n; i++) {
    cin >> p.name >> p.time;
    queue.enqueue(p);
    // queue.PrintQueue();
  }
  // cout << n << " " << q << endl;
  // queue.PrintQueue();

  int t = 0;
  while (!queue.isEmpty()) {
    p = queue.dequeue();
    if (p.time >= q) {
      t += q;
      p.time -= q;
    } else {
      t += p.time;
      p.time = 0;
    }

    if (p.time <= 0) {
      printf("%s %d\\n", p.name, t);
      // cout << p.name << " " << t << endl;
    } else {
      queue.enqueue(p);
    }
  }
  return 0;
}
Problem p02264 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define LEN 100005

typedef struct {
  string name;
  int time;
} Process;

Process Que[LEN];
int head, tail, n;

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

Process dequeue() {
  Process x = Que[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 q;
  Process u;
  cin >> n >> q;

  for (int i = 1; i <= n; i++) {
    cin >> Que[i].name >> Que[i].time;
  }
  head = 1;
  tail = n + 1;

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

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef struct {
  string name;
  int time;
} Process;

int main() {
  Process ps1[100005];
  int n, q;
  int time = 0;
  int head, tail;
  int i = 0;

  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    cin >> ps1[i].name >> ps1[i].time;
  }

  head = 0;
  tail = n;

  while (ps1[head].time > 0 && i < n) {
    ps1[head].time -= q;
    if (ps1[head].time <= 0) {
      time += q + ps1[head].time;
      ps1[i].time = time;
      ps1[i++].name = ps1[head].name;
    } else {
      time += q;
      ps1[tail++] = ps1[head];
    }
    head++;
  }

  for (int j = 0; j < n; j++) {
    cout << ps1[j].name << ' ' << ps1[j].time << endl;
  }

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

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

using namespace std;

int main() {
  string word, wordk;
  int num;
  queue<int> S;
  queue<string> M;
  int n, q, k;
  int timeS = 0;
  int timeN = 0;
  cin >> n >> q;
  for (int i = 0; i < n; ++i) {
    // S???time???M???name?????\\???
    cin >> word;
    M.push(word);
    cin >> num;
    // time???????¨???????????????????
    timeS += num;
    S.push(num);
  }
  while (S.front() > 0 && !S.empty()) {
    if (S.front() > q) {
      k = S.front();
      S.pop();
      S.push(k - q);
      wordk = M.front();
      M.pop();
      M.push(wordk);
      timeN += q;
    } else {
      timeN += S.front();
      cout << M.front() << " " << timeN << endl;

      S.pop();
      M.pop();
    }
  }
}

Error: 0

Fixed submission:

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

using namespace std;

int main() {
  string word, wordk;
  int num;
  queue<int> S;
  queue<string> M;
  int n, q, k;
  int timeS = 0;
  int timeN = 0;
  cin >> n >> q;
  for (int i = 0; i < n; ++i) {
    // S???time???M???name?????\\???
    cin >> word;
    M.push(word);
    cin >> num;
    // time???????¨???????????????????
    timeS += num;
    S.push(num);
  }
  while (S.front() > 0) {
    if (S.front() > q) {
      k = S.front();
      S.pop();
      S.push(k - q);
      wordk = M.front();
      M.pop();
      M.push(wordk);
      timeN += q;
    } else {
      timeN += S.front();
      cout << M.front() << " " << timeN << endl;
      S.pop();
      M.pop();
    }
  }
}
Problem p02264 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

struct Task {
  char name[10];
  int rtime;
};

Task task[100000];
int head, tail, n, q, len = 100000;

void unit() {
  head = 0;
  tail = 0;
  cin >> n >> q;
}
void enquene(Task t) {
  task[tail] = t;
  tail = (tail + 1) % len;
}

Task dequene() {
  Task t = task[head];
  head = (head + 1) % len;
  return t;
}

int main() {
  unit();
  Task t;
  int ftime = 0;
  for (int i = 0; i < n; i++) {
    cin >> t.name;
    cin >> t.rtime;
    enquene(t);
  }
  while (head != tail) {
    t = dequene();
    if (t.rtime > q) {
      t.rtime -= q;
      ftime += q;
      enquene(t);
    } else {
      ftime += t.rtime;
      cout << t.name << " " << ftime << endl;
    }
  }
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;

struct Task {
  char name[10];
  int rtime;
};

Task task[100000];
int head, tail, n, q, len = 1000001;

void unit() {
  head = 0;
  tail = 0;
  cin >> n >> q;
}
void enquene(Task t) {
  task[tail] = t;
  tail = (tail + 1) % len;
}

Task dequene() {
  Task t = task[head];
  head = (head + 1) % len;
  return t;
}

int main() {
  unit();
  Task t;
  int ftime = 0;
  for (int i = 0; i < n; i++) {
    cin >> t.name;
    cin >> t.rtime;
    enquene(t);
  }
  while (head != tail) {
    t = dequene();
    if (t.rtime > q) {
      t.rtime -= q;
      ftime += q;
      enquene(t);
    } else {
      ftime += t.rtime;
      cout << t.name << " " << ftime << endl;
    }
  }
  return 0;
}
Problem p02264 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n, q, i, d, sum, tmp;
  cin >> n >> q;
  vector<int> times(n);
  vector<string> names(n);
  for (i = 0; i < n; i++) {
    cin >> names[i] >> times[i];
  }

  sum = 0;
  for (i = 0; i < n; i++) {
    d = q - times[i];
    if (d >= 0) {
      sum += times[i];
      cout << names[i] << " " << sum << endl;
    } else {
      sum += q;
      tmp = d * (-1);
      times.push_back(tmp);
      names.push_back(names[i]);
      n++;
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int n, q, i, d, sum, tmp;
  cin >> n >> q;
  vector<int> times(n);
  vector<string> names(n);

  for (i = 0; i < n; i++) {
    cin >> names[i] >> times[i];
  }

  sum = 0;
  while (1) {
    d = q - times[0];
    if (d >= 0) {
      sum += times[0];
      cout << names[0] << " " << sum << endl;
    } else {
      sum += q;
      tmp = d * (-1);
      times.push_back(tmp);
      names.push_back(names[0]);
    }
    times.erase(times.begin());
    names.erase(names.begin());
    if (times.empty())
      break;
  }
  return 0;
}
Problem p02264 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

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

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

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

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);
  }

  c = 0;
  head = 1;
  tail = n + 1;

  while (1) {
    u = dequeue();
    if ((u.t - q) > 0) {
      u.t -= q;
      enqueue(u);
      elaps += q;
    } else {
      elaps += u.t;
      printf("%s %d\\n", u.name, elaps);
      c++;
    }
    if (c == n)
      break;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 100000

void initialize(void);
int isEmpty(void);
int isFull(void);
void enqueue(int x);
int dequeue(void);

int Q[MAX];
int head;
int tail;

int main() {
  int i;
  int n, q;
  int x;
  int sum = 0;
  int flag = 0;
  int count = 0;

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

  if (n < 1 || 100000 < n || q < 1 || 1000 < q) {
    exit(0);
  }

  char name[n][10];
  int time[n];
  int skip[n];

  for (i = 0; i < n; i++) {
    scanf("%s", name[i]);
    scanf("%d", &time[i]);
    enqueue(time[i]);
    skip[i] = 0;
  }

  while (1) {

    for (i = 1; i < n + 1; i++) {
      flag = 0;
      for (int j = 0; j < n; j++) {
        if (i == skip[j]) {
          flag = 1;
          break;
        }
      }
      if (flag == 1)
        continue;

      x = dequeue();

      if ((x - q) > 0) {
        enqueue(x - q);
        sum += q;
      } else {
        sum += x;
        printf("%s %d\\n", name[i - 1], sum);
        skip[i - 1] = i;
        count++;
      }
    }
    if (count == n)
      break;
  }

  return 0;
}

void initialize() { head = tail = 0; }

int isEmpty() { return head == tail; }

int isFull() { return head == (tail + 1) % MAX; }

void enqueue(int x) {
  if (isFull()) {
    exit(1);
  }
  Q[tail] = x;
  if ((tail + 1) == MAX) {
    tail = 0;
  } else
    tail++;
}

int dequeue() {
  int x;
  if (isEmpty()) {
    exit(2);
  }
  x = Q[head];
  if ((head + 1) == MAX) {
    head = 0;
  } else
    head++;
  return x;
}