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

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define MAX 100000
int ti[100000], a = 0, e = 0, deqti;
string name[MAX], deqname;
void enq(int n, string na) {
  ti[e] = n;
  name[e] = na;
  e = (e + 1) % MAX;
}
void deq() {
  deqti = ti[a];
  deqname = name[a];
  a = (a + 1) % MAX;
}

int main() {
  int timecnt = 0, n, quantum, itime;
  string str;
  cin >> n >> quantum;
  for (int i = 0; i < n; i++) {
    cin >> str >> itime;
    enq(itime, str);
  }
  while (true) {
    deq();
    if (deqti - quantum <= 0) {
      int t = deqti;
      timecnt += t;
      cout << deqname << " " << timecnt << endl;
    } else {
      timecnt += quantum;
      enq(deqti - quantum, deqname);
    }
    if (a == e)
      break;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
int ti[100000], a = 0, e = 0, deqti;
string name[100000], deqname;
void enq(int n, string na) {
  ti[e] = n;
  name[e] = na;
  e++;
}
void deq() {
  deqti = ti[a];
  deqname = name[a];
  a++;
}

int main() {
  int timecnt = 0, n, quantum, itime;
  string str;
  cin >> n >> quantum;
  for (int i = 0; i < n; i++) {
    cin >> str >> itime;
    enq(itime, str);
  }
  while (true) {
    deq();
    if (deqti - quantum <= 0) {
      int t = deqti;
      timecnt += t;
      cout << deqname << " " << timecnt << endl;
    } else {
      timecnt += quantum;
      enq(deqti - quantum, deqname);
    }
    if (a == e)
      break;
  }
  return 0;
}
Problem p02264 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <queue>
using namespace std;
int main() {
  int n, t, p, c = 0;
  string s;
  cin >> n >> t;
  queue<pair<string, int>> a;
  while (n--) {
    cin >> s >> p;
    a.push(make_pair(s, p));
  }
  while (!a.empty()) {
    pair<string, int> b = a.front();
    a.pop();
    if (b.second <= t) {
      c += b.second;
      cout << b.first << ' ' << c << endl;
    } else {
      b.second -= t;
      c += t;
      a.push(b);
    }
  }
}


Error: TLE

Fixed submission:

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

int main() {
  vector<int> time(100001);
  vector<string> name(100001);
  int n, qo, q, timesum = 0, z = 0;
  cin >> n >> qo;

  for (int i = 0; i < n; i++) {
    cin >> name[i] >> time[i];
  }
  while (time[n - 1] > 0) {
    if (time[n - 1] <= 0)
      break;
    q = qo;
    if (time[z] <= qo) {
      q -= time[z];
      timesum += time[z];
      cout << name[z] << " " << timesum << "\\n";
      if (z == n - 1)
        break;
      z++;
    } else if (time[z] > q) {
      time[z] -= qo;
      timesum += qo;
      for (int j = z; j < n - 1; j++) {
        swap(name[j], name[j + 1]);
        swap(time[j], time[j + 1]);
      }
    }
  }
  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];
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);
    u.t -= c;
    elaps += c;
    if (u.t > 0)
      enqueue(u);
    else {
      printf("%s %d\\n", u.name, elaps);
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

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

int main(void) {
  int n, q, time[100000], i, j = 0, k, t = 0;
  char name[100000][10];

  scanf("%d %d", &n, &q);
  for (i = 0; i < n; i++) {
    scanf("%s %d", name[i], &time[i]);
  }
  i = 0;
  while (j < n) {
    if (time[i] == 0)
      ;
    else if (time[i] <= q && time[i] > 0) {
      t += time[i];
      printf("%s %d\\n", name[i], t);
      time[i] = 0;
      j++;
    } else if (time[i] > q) {
      t += q;
      time[i] -= q;
    }
    i++;
    if (i > n)
      i = 0;
  }
  return 0;
}
Problem p02264 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

#define QSIZE 100000
struct Task {
  string name;
  int time;
  Task(string n, int t) : name(n), time(t) {}
  Task() {}
};

Task queue[QSIZE + 1];
int head, tail;

void enqueue(Task data) {
  queue[tail] = data;
  tail = (tail + 1) % QSIZE;
}

Task dequeue() {
  Task res = queue[head];
  head = (head + 1) % QSIZE;
  return res;
}

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

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

  for (int i = 0; i < N; i++) {
    string name;
    int time;
    cin >> name >> time;
    enqueue(Task(name, time));
  }

  int time = 0;
  while (!isEmpty()) {
    Task t = dequeue();
    if (t.time > Q) {
      enqueue(Task(t.name, t.time - Q));
      time += Q;
    } else {
      time += t.time;
      cout << t.name << " " << time << endl;
    }
  }
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

#define MAX_DATA_NUM 100000
struct Task {
  string name;
  int time;
  Task(string n, int t) : name(n), time(t) {}
  Task() {}
};

Task queue[MAX_DATA_NUM];
int head, tail;

void enqueue(Task data) {
  queue[tail] = data;
  tail++;
}

Task dequeue() {
  Task res = queue[head];
  head++;
  return res;
}

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

  for (int i = 0; i < N; i++) {
    string name;
    int time;
    cin >> name >> time;
    enqueue(Task(name, time));
  }

  int time = 0;
  while (head < tail) {
    Task t = dequeue();
    if (t.time > Q) {
      enqueue(Task(t.name, t.time - Q));
      time += Q;
    } else {
      time += t.time;
      cout << t.name << " " << time << endl;
    }
  }
}
Problem p02264 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>
#define max 100000

using namespace std;

int head, tail, a_size;

struct Ps {
  string name;
  int times;
};

Ps ps[max];

void enqueue(Ps p) {
  ps[tail] = p;
  ++tail;
  tail %= max;
}

Ps dequenue() {
  Ps p = ps[head];
  ++head;
  head %= max;
  return p;
}

int main() {
  int q_time, el_time = 0, n_time;
  Ps ps_af;
  cin >> a_size >> q_time;
  for (int i = 1; i <= a_size; ++i) {
    cin >> ps[i].name >> ps[i].times;
  }
  head = 1;
  tail = a_size + 1;

  while (head != tail) {
    ps_af = dequenue();
    n_time = min(q_time, ps_af.times);
    ps_af.times -= n_time;
    el_time += n_time;
    if (ps_af.times > 0)
      enqueue(ps_af);
    else
      cout << ps_af.name << " " << el_time << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#define max 100000

using namespace std;

int head, tail, a_size;

struct Ps {
  string name;
  int times;
};

Ps ps[max];

void enqueue(Ps p) {
  ps[tail] = p;
  ++tail;
}

Ps dequenue() {
  Ps p = ps[head];
  ++head;
  return p;
}

int main() {
  int q_time, el_time = 0, n_time;
  Ps ps_af;
  cin >> a_size >> q_time;
  for (int i = 1; i <= a_size; ++i) {
    cin >> ps[i].name >> ps[i].times;
  }
  head = 1;
  tail = a_size + 1;

  while (head != tail) {
    ps_af = dequenue();
    n_time = min(q_time, ps_af.times);
    ps_af.times -= n_time;
    el_time += n_time;
    if (ps_af.times > 0)
      enqueue(ps_af);
    else
      cout << ps_af.name << " " << el_time << endl;
  }
  return 0;
}
Problem p02264 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;
#define LEN 1000000

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

P Q[LEN];
int head = 0;
int tail = 0;

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 argc, const char *argv[]) {
  int n, q;
  int elaps = 0;

  cin >> n >> q;

  for (int i = 0; i < n; i++) {
    cin >> Q[i].name >> Q[i].time;
    enqueue(Q[i]);
  }
  tail = n;
  while (head != tail) {
    P p = dequeue();
    int mtime = min(p.time, q);
    elaps += mtime;
    p.time -= mtime;
    if (p.time > 0) {
      enqueue(p);
    } else {
      cout << p.name << " " << elaps << endl;
    }
  }

  return 0;
}


Error: 0

Fixed submission:

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

static const int MAX = 10000;
using namespace std;
int LEN = 10000;

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

P Q[MAX];
int head = 0;
int tail = 0;

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 argc, const char *argv[]) {
  int n, q;
  int elaps = 0;

  cin >> n >> q;

  for (int i = 0; i < n; i++) {
    cin >> Q[i].name >> Q[i].time;
    enqueue(Q[i]);
  }
  tail = n;
  while (head != tail) {
    P p = dequeue();
    int mtime = min(p.time, q);
    elaps += mtime;
    p.time -= mtime;
    if (p.time > 0) {
      enqueue(p);
    } else {
      cout << p.name << " " << elaps << endl;
    }
  }

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

#include <iostream>
using namespace std;

struct process {
  char name[10];
  int time;
  process *next;
  process *prev;
};

int main() {

  process job[100002];

  int timer = 0;
  int numOfJob;
  int quantum;

  cin >> numOfJob;
  cin >> quantum;

  for (int i = 1; i <= numOfJob; i++) {
    cin >> job[i].name;
    cin >> job[i].time;
    job[i].next = &job[i + 1];
    job[i].prev = &job[i - 1];
  }

  job[numOfJob].next = &job[1];
  job[1].prev = &job[numOfJob];

  process *cjob = &job[1];

  while (cjob->next != cjob) {

    // cout<< cjob->prev->name << " <=prev= " << cjob->name << " =next=> " <<
    // cjob->next->name << endl;

    if (cjob->time > quantum) {
      cjob->time -= quantum;
      timer += quantum;
    } else {
      timer += cjob->time;
      cout << cjob->name << " " << timer << endl;
      cjob->prev->next = cjob->next;
      cjob->next->prev = cjob->prev;
    }
    cjob = cjob->next;
  }
  cout << cjob->name << " " << timer + cjob->time << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

struct process {
  char name[10];
  int time;
};

int main() {

  process job[100000];

  int timer = 0;
  int jobCounter;
  int numOfJob;
  int quantum;
  int index = 0;

  cin >> numOfJob;
  cin >> quantum;

  for (int i = 0; i < numOfJob; i++) {
    cin >> job[i].name;
    cin >> job[i].time;
  }

  jobCounter = numOfJob;
  index = 0;
  while (jobCounter > 0) {
    /*
    cout << "index is " << index << " Job counter is " << jobCounter << endl;
    for(int i = 0; i < jobCounter; i++){
            cout << job[i].name << " " << job[i].time << endl;
    }
    cout << endl;
    */
    if (job[index].time > quantum) {
      job[index].time = job[index].time - quantum;
      timer += quantum;

      index++;
    } else {
      timer += job[index].time;
      job[index].time = 0;

      cout << job[index].name << " " << timer << endl;

      for (int i = index; i < jobCounter - 1; i++)
        job[i] = job[i + 1];
      jobCounter--;
    }

    if (index > jobCounter - 1)
      index = 0;
  }

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

#include <stdio.h>
#include <stdlib.h>

#define MAXQUEUE 100000

struct Process {
  char name[10];
  int time;
};

int main() {
  int N, q;
  int totalTime = 0;
  struct Process queue[MAXQUEUE];
  int beginP, endP;
  scanf("%d %d", &N, &q);
  for (int i = 0; i < N; i++) {
    scanf("%s %d", queue[i].name, &queue[i].time);
  }
  beginP = 0;
  endP = N;
  while (endP - beginP) {
    if (queue[beginP].time <= q) {
      totalTime += queue[beginP].time;
      printf("%s %d\\n", queue[beginP].name, totalTime);
      if (beginP == MAXQUEUE - 1)
        beginP = 0;
      else
        beginP = beginP + 1;
    } else {

      queue[beginP].time -= q;
      queue[endP] = queue[beginP];
      endP = (endP + 1) % MAXQUEUE;
      beginP = (beginP + 1) % MAXQUEUE;
      totalTime += q;
    }
  }

  return 0;
}


Error: 0

Fixed submission:

#include <stdio.h>
#include <stdlib.h>

#define MAXQUEUE 70000

struct Process {
  char name[10];
  int time;
};

int main() {
  int N, q;
  int totalTime = 0;
  int flag = 0;
  struct Process queue[MAXQUEUE];
  int beginP, endP;
  scanf("%d %d", &N, &q);
  for (int i = 0; i < N; i++) {
    scanf("%s %d", queue[i].name, &queue[i].time);
  }
  beginP = 0;
  endP = N;
  while (flag < N) {
    if (queue[beginP].time <= q) {
      totalTime += queue[beginP].time;
      printf("%s %d\\n", queue[beginP].name, totalTime);
      beginP++;
      flag++;
    } else {
      if (endP >= MAXQUEUE) {
        endP = 0;
      }
      queue[beginP].time -= q;
      queue[endP] = queue[beginP];
      endP++;
      beginP++;
      totalTime += q;
    }
  }

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

#include <iostream>
#include <string>

using namespace std;

#define SIZE 100000
#define P pair<string, int>

P que[SIZE];
int head = 0, tail = 0;

void push(P v) {
  que[tail] = v;
  tail = (tail + 1) % SIZE;
}

P pop() {
  P t = que[head];
  head = (head + 1) % SIZE;
  return t;
}

bool isEmpty() {
  if (head == tail)
    return true;
  return false;
}

int main() {
  int n, q, v;
  string s;
  cin >> n >> q;
  while (n--) {
    cin >> s >> v;
    push(P(s, v));
  }
  P p;
  int sum = 0;
  while (!isEmpty()) {
    p = pop();
    if (p.second > q) {
      p.second -= q;
      sum += q;
      push(p);
    } else {
      cout << p.first << " " << p.second + sum << endl;
      sum += p.second;
    }
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define ll long long
#define ull unsigned long long
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define eps 1e-9
#define P pair<int, int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)

void YES() { cout << "YES\\n"; }
void NO() { cout << "NO\\n"; }
void Yes() { cout << "Yes\\n"; }
void No() { cout << "No\\n"; }

pair<int, string> p[100000];

int main() {
  int n, q, t;
  queue<P> que;

  cin >> n >> q;
  for (int i = 0; i < n; ++i) {
    cin >> p[i].second >> t;
    que.push(make_pair(t, i));
  }

  while (!que.empty()) {
    P f = que.front();
    que.pop();
    if (f.first > q) {
      for (int i = 0; i < que.size(); ++i) {
        P g = que.front();
        que.pop();
        p[g.second].first += q;
        que.push(g);
      }
      p[f.second].first += q;
      f.first -= q;
      que.push(f);
    } else {
      for (int i = 0; i < que.size(); ++i) {
        P g = que.front();
        que.pop();
        p[g.second].first += f.first;
        que.push(g);
      }
      p[f.second].first += f.first;
    }
  }

  sort(p, p + n);

  for (int i = 0; i < n; ++i) {
    cout << p[i].second << " " << p[i].first << endl;
  }

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

#include <iostream>
#include <stdlib.h>

#define N_MAX 99999

using namespace std;

typedef struct _a {
  char name[10];
  int time;
} P;

int main() {

  int i;
  int n;
  int q;
  int head;
  int tail;
  int res_time = 0;
  char temp[10];
  P A[N_MAX];

  cin >> n;
  cin >> q;

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

  head = 0;
  tail = n - 1;

  while (1) {
    // process
    // ??????????????´??°
    A[head].time -= q;

    // ????????????
    if (A[head].time <= 0) {
      res_time += q + A[head].time;
      cout << A[head].name << ' ' << res_time << endl;
      if (tail == head) {
        break;
      }
    } else {
      // ?????£?????´??°
      tail++;
      if (tail == N_MAX) {
        tail = 0;
      }
      A[tail] = A[head];
      res_time += q;
    }

    // ?????´??°
    head++;
    if (head == N_MAX) {
      head = 0;
    }
  }

  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
#include <stdlib.h>

#define N_MAX 1000000

using namespace std;

typedef struct _a {
  char name[10];
  int time;
} P;

int main() {

  int i;
  int n;
  int q;
  int head;
  int tail;
  int res_time = 0;
  char temp[10];
  P A[N_MAX];

  cin >> n;
  cin >> q;

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

  head = 0;
  tail = n - 1;

  while (1) {
    // process
    // ??????????????´??°
    A[head].time -= q;

    // ????????????
    if (A[head].time <= 0) {
      res_time += q + A[head].time;
      cout << A[head].name << ' ' << res_time << endl;
      if (tail == head) {
        break;
      }
    } else {
      // ?????£?????´??°
      tail++;
      if (tail == N_MAX) {
        tail = 0;
      }
      A[tail] = A[head];
      res_time += q;
    }

    // ?????´??°
    head++;
    if (head == N_MAX) {
      head = 0;
    }
  }

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

#include <algorithm>
#include <deque>
#include <iostream>
#include <string>

using namespace std;

struct Task {
  string name;
  int time;
  Task(string name, int time) : name(name), time(time) {}
};

struct RoundRobin {
  const int maxDur;
  int time;
  deque<Task> data;

  RoundRobin(int dur) : maxDur(dur), time(0) {}
  void addTask(Task t) { this->data.push_back(t); }
  void doSchedule() {
    while (not this->data.empty()) {
      auto task = this->data.front();
      this->time += min(task.time, maxDur);
      int rem = task.time - this->maxDur;
      if (rem > 0) {
        task.time = rem;
        this->data.push_back(task);
      } else {
        cout << task.name << " " << this->time << endl;
      }
      this->data.pop_front();
    }
  }
};

int main() {
  int n, q;
  cin >> n >> q;

  RoundRobin rr(q);

  string name;
  int time;
  for (int i = 0; i < n; i++) {
    cin >> name >> time;
    Task t(name, time);
    rr.addTask(t);
  }

  rr.doSchedule();

  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

struct Task {
  string name;
  int time;
  Task(string name, int time) : name(name), time(time) {}
};

struct RoundRobin {
  const int maxDur;
  int time;
  vector<Task> data;

  RoundRobin(int dur) : maxDur(dur), time(0) {}
  void addTask(Task t) { this->data.push_back(t); }
  void doSchedule() {
    while (not this->data.empty()) {
      auto task = this->data[0];
      this->time += min(task.time, maxDur);
      int rem = task.time - this->maxDur;
      if (rem > 0) {
        task.time = rem;
        this->data.push_back(task);
      } else {
        cout << task.name << " " << this->time << endl;
      }
      this->data.erase(this->data.begin());
    }
  }
};

int main() {
  int n, q;
  cin >> n >> q;

  RoundRobin rr(q);

  string name;
  int time;
  for (int i = 0; i < n; i++) {
    cin >> name >> time;
    Task t(name, time);
    rr.addTask(t);
  }

  rr.doSchedule();

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

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

int main() {
  int n, q;
  std::cin >> n >> q;

  std::vector<std::string> names(n);
  std::vector<int> times(n);
  int val, buf, totalTime = 0;
  for (int i = 0; i < n; ++i) {
    std::cin >> names.at(i) >> val;
    buf = std::min(q, val);
    totalTime += buf;
    times.at(i) = val - buf;
    if (0 == times.at(i)) {
      std::cout << names.at(i) << " " << totalTime << std::endl;
    }
  }

  //    std::cout << "------" << std::endl;

  while (1) {
    std::vector<int>::iterator itr = std::find_if(
        times.begin(), times.end(), [](int elem) { return 0 != elem; });

    if (times.end() == itr) {
      break;
    } else {

      //            std::cout << "flag" << std::endl;

      while (times.end() != itr) {
        //                for(int i = 0; i < n; ++i){
        //                    std::cout << names.at(i) << " " << times.at(i) <<
        //                    " / ";
        //                }
        //                std::cout << std::endl;

        buf = std::min(q, *itr);
        *itr -= buf;
        totalTime += buf;
        if (0 == *itr) {
          int i = std::distance(times.begin(), itr);
          std::cout << names.at(i) << " " << totalTime << std::endl;
        }
        ++itr;
        itr =
            std::find_if(itr, times.end(), [](int elem) { return 0 != elem; });
      }
    }
  }

  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int n, q;
  std::cin >> n >> q;

  std::vector<std::string> names(n);
  std::vector<int> times(n);
  std::vector<bool> flags(n, false);
  for (int i = 0; i < n; ++i) {
    std::cin >> names.at(i) >> times.at(i);
  }

  int totalTime = 0;
  while (flags.end() != std::find(flags.begin(), flags.end(), false)) {
    std::vector<bool>::iterator itr = flags.begin();
    while (flags.end() != itr) {
      itr = std::find(itr, flags.end(), false);
      int i = std::distance(flags.begin(), itr);
      if (i < n) {
        if (!*itr) {
          totalTime += std::min(times.at(i), q);
          if (times.at(i) <= q) {
            std::cout << names.at(i) << " " << totalTime << std::endl;
            *itr = true;
          }
          times.at(i) -= std::min(times.at(i), q);
        }
        ++itr;
      }
    }
  }

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

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

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;
struct P {
  char name[11];
  int time;
};
int main() {

  P a[100000];
  int i, n, q, c = 0, time = 0;
  scanf("%d%d", &n, &q);
  // cin>>n>>q;
  for (i = 0; i < n; i++)
    scanf("%s%d", a[i].name, &a[i].time);
  // cin>>a[i].name>>a[i].time;
  for (i = 0; c != n; i++) {
    if (i == n)
      i = 0;
    if (a[i].time == 0)
      continue;
    else if (a[i].time <= q) {
      time += a[i].time;
      a[i].time = 0;
      printf("%s %d\\n", a[i].name, time);
      // cout<<a[i].name<<' '<<time<<endl;
      ++c;
    } else {
      time += q;
      a[i].time -= q;
    }
  }
  return 0;
}