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

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

pair<string, int> process1, process2;
queue<pair<string, int>> Q;
int main() {
  int j = 0, sum = 0;
  int n, t, flag = 0;
  cin >> n >> t;
  for (int i = 0; i < n; i++) {
    cin >> process1.first >> process1.second;
    Q.push(process1);
  }
  while (!Q.empty()) {
    process2 = Q.front();
    Q.pop();
    if (process2.second > t) {
      process2.second -= t;
      sum += t;
      Q.push(process2);
    } else {
      sum += process2.second;
      cout << process2.first << " " << sum << endl;
    }
  }
  return 0;
}


Error: 1

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int n, q;
pair<string, int> process, temp;
queue<pair<string, int>> Q;
void solve() {
  int time = 0;
  while (!Q.empty()) {
    temp = Q.front();
    Q.pop();
    if (temp.second <= q) {
      time += temp.second;
      cout << temp.first << ' ' << time << endl;
    } else {
      time += q;
      temp.second -= q;
      Q.push(temp);
    }
  }
}
int main() {
  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    cin >> process.first >> process.second;
    Q.push(process);
  }
  solve();
  return 1;
}
Problem p02264 (C++) — buggy submission, verdict: Runtime Error

#include <cassert>
#include <iostream>
// #include <queue>

#define INF 922337203685477580
#define N 1100000
typedef long long ll;

using namespace std;

struct Task {
  string task;
  int cost;
};
struct Task queue[N];
int head = 0;
int tail = 0;

void enqueue(Task t) {
  queue[tail] = t;
  tail = (tail + 1) % N;
}
struct Task dequeue() {
  head = (head + 1) % N;
  return queue[head - 1];
}
int isEmpty() { return head == tail; }

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

  struct Task T[n];

  for (int i = 0; i < n; i++) {
    cin >> T[i].task >> T[i].cost;
  }
  for (int i = 0; i < n; i++) {
    enqueue(T[i]);
  }

  ll elapsed = 0L;

  while (!isEmpty()) {
    struct Task t = dequeue();
    if (t.cost > q) {
      struct Task newT = {t.task, t.cost - q};
      enqueue(newT);
      elapsed += q;
    } else {
      elapsed += t.cost;
      cout << t.task << " " << elapsed << endl;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <cassert>
#include <iostream>
// #include <queue>

#define INF 922337203685477580
typedef long long ll;

using namespace std;

struct Task {
  string task;
  int cost;
};
struct Task queue[110000];
int head = 0;
int tail = 0;

void enqueue(Task t) {
  queue[tail] = t;
  tail = (tail + 1) % 110000;
}
struct Task dequeue() {
  head = (head + 1) % 110000;
  return queue[head - 1];
}
int isEmpty() { return head == tail; }

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

  struct Task T[n];

  for (int i = 0; i < n; i++) {
    cin >> T[i].task >> T[i].cost;
  }
  for (int i = 0; i < n; i++) {
    enqueue(T[i]);
  }

  ll elapsed = 0L;

  while (!isEmpty()) {
    struct Task t = dequeue();
    if (t.cost > q) {
      struct Task newT = {t.task, t.cost - q};
      enqueue(newT);
      elapsed += q;
    } else {
      elapsed += t.cost;
      cout << t.task << " " << elapsed << endl;
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
struct proccess {
  string name;
  int time;
  // int excutetime;
  int id;
};

bool cmp(proccess a, proccess b) { return a.id < b.id; }

// void excute(vector<proccess> &prs, int t)
// {
//   for (proccess &p : prs)
//   {
//     p.excutetime += t;
//   }
// }

int main() {
  int n, q;
  cin >> n >> q;
  vector<proccess> prs(n);
  // sort(prs.begin(), prs.end(), cmp);
  for (proccess &pp : prs) {
    static int i = 0;
    cin >> pp.name >> pp.time;
    // pp.excutetime = 0;
    pp.id = i;
    i++;
  }
  queue<proccess> qu;

  for (proccess p : prs) {
    qu.push(p);
  }

  // stringstream result;

  while (not qu.empty()) {
    static int elaps = 0;
    proccess p = qu.front();
    qu.pop();

    if (p.time > q) {
      p.time -= q;

      elaps += q;
      // excute(prs, q);

      // lout << "DEBUG " << p.name << "," << p.time << "," << p.excutetime <<
      // endl;
      qu.push(p);
    } else {
      elaps += p.time;
      // p.excutetime += p.time;
      // excute(prs, p.time);
      //  for (proccess p_ : prs)
      //  {
      //    if (p_.name == p.name)
      //    {
      //      ext = p_.excutetime;
      //      break;
      //    }
      //  }

      /// int ext = prs[lower_bound(prs.begin(), prs.end(), p,
      /// cmp)->id].excutetime;
      cout << p.name << " " << elaps << endl;
      // printf("%s %d/n", p.name.c_str(), elaps);
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
struct proccess {
  string name;
  int time;
  int excutetime;
};

void excute(vector<proccess> &qu, int t) {
  for (proccess &p_ : qu) {
    p_.excutetime += t;
  }
}

int main() {
  int n, q;
  cin >> n >> q;
  vector<proccess> prs(n);
  for (proccess &pp : prs) {
    cin >> pp.name >> pp.time;
    pp.excutetime = 0;
  }
  vector<proccess> qu(n);

  qu = prs;

  while (not qu.empty()) {
    proccess p = qu[0];
    qu.erase(qu.begin(), qu.begin() + 1);
    // p.running = true;
    if (p.time > q) {
      p.time -= q;
      p.excutetime += q;
      excute(qu, q);

      // cout << "DEBUG " << p.name << "," << p.time << "," << p.excutetime <<
      // endl;
      qu.push_back(p);
    } else {
      p.excutetime += p.time;
      excute(qu, p.time);
      cout << p.name << " " << p.excutetime << endl;
    }
  }

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

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

using namespace std;

int main() {

  int n, q, t;
  string name;
  queue<pair<string, int>> Q;

  cin >> n >> q;

  for (int i = 0; i < n; i++) {
    cin >> name >> t;
    Q.push(make_pair(name, t));
  }
  pair<string, int> u;
  int elaps = 0;
  int a = 0;

  while (!Q.empty()) {
    u = Q.front();
    Q.pop();
    a = min(u.second, q);
    u.second -= a;
    elaps += a;
    if (u.second > 0) {
      Q.push(u);
    } else {
      cout << u.first << " " << elaps << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

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

struct Proc {
  char name[100];
  int t;
};

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

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

Proc dequeue() {
  Proc 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;
  Proc u;
  int n, q;

  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 = 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 <algorithm>
#include <iostream>
using namespace std;
static const int MAX = 100001;

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

struct task que[MAX];
int head = 0;
int tail = 0;

int increment(int p) { return (p + 1) % MAX; }

void enqueue(struct task t) {
  que[tail] = t;
  tail = increment(tail);
}

struct task dequeue() {
  int pre = head;
  head = increment(head);
  return que[pre];
}

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

int main() {
  int n, q;
  cin >> n;
  cin >> q;
  struct task t;
  for (int i = 0; i < n; i++) {
    cin >> t.name;
    cin >> t.time;
    enqueue(t);
  }

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

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
static const int MAX = 100001;

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

struct task que[MAX];
int head = 0;
int tail = 0;

int increment(int p) { return (p + 1) % MAX; }

void enqueue(struct task t) {
  que[tail] = t;
  tail = increment(tail);
}

struct task dequeue() {
  int pre = head;
  head = increment(head);
  return que[pre];
}

void print(struct task t) {
  cout << t.name << " ";
  cout << t.time << endl;
}

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

int main() {
  int n, q;
  cin >> n;
  cin >> q;
  struct task t;
  for (int i = 0; i < n; i++) {
    cin >> t.name;
    cin >> t.time;
    enqueue(t);
  }

  int elaps;
  int total = 0;
  int i;
  struct task tasks[n];
  while (!isEmpty()) {
    t = dequeue();
    elaps = min(t.time, q);
    t.time -= elaps;
    total += elaps;
    if (t.time > 0) {
      enqueue(t);
    } else {
      t.time = total;
      tasks[i] = t;
      i++;
    }
  }

  for (int i = 0; i < n; i++) {
    print(tasks[i]);
  }
}
Problem p02264 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>

using namespace std;

const int con = 100002;

struct process {
  string name;
  int time;
};

class queue {
public:
  process q[con];
  int tail, head;
  void initialize();
  void enqueue(process x);
  process dequeue();
};

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

void queue::enqueue(process x) {
  q[tail] = x;
  if (tail + 1 == con) {
    tail = 0;
  } else {
    tail++;
  }
}

process queue::dequeue() {
  process x;
  x = q[head];

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

  return x;
}

int main() {
  int n, q, nowtime, j = 0;
  process p[100000], result[100000], temp;
  queue que;

  que.initialize();

  cin >> n >> q;

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

  while (que.tail != que.head) {
    temp = que.dequeue();

    if (temp.time - q <= 0) {
      nowtime += temp.time;

      /*result[j].name = temp.name;
      result[j].time = nowtime;
      j++;
      */

      cout << temp.name << " " << nowtime << "\\n";

    } else {
      temp.time -= q;
      nowtime += q;
      que.enqueue(temp);
    }
  }

  /*for(int i = 0; i < n; i++)
  {
          cout << result[i].name << " " << result[i].time <<"\\n";
  }*/

  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

const int con = 50000;

struct process {
  string name;
  int time;
};

class queue {
public:
  process q[con];
  int tail, head;
  void initialize();
  void enqueue(process x);
  process dequeue();
};

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

void queue::enqueue(process x) {
  q[tail] = x;
  tail++;
}

process queue::dequeue() {
  process x;
  x = q[head];

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

  return x;
}

int main() {
  int n, q, nowtime, j = 0;
  process p[100000], result[100000], temp;
  queue que;

  que.initialize();

  cin >> n >> q;

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

  while (que.tail != que.head) {
    temp = que.dequeue();

    if (temp.time - q <= 0) {
      nowtime += temp.time;

      /*result[j].name = temp.name;
      result[j].time = nowtime;
      j++;
      */

      cout << temp.name << " " << nowtime << "\\n";

    } else {
      temp.time -= q;
      nowtime += q;
      que.enqueue(temp);
    }
  }

  /*for(int i = 0; i < n; i++)
  {
          cout << result[i].name << " " << result[i].time <<"\\n";
  }*/

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

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

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

int main(int argc, char **argv) {

  list<pro> l;
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    pro tmp1;
    char tmp2[10];
    int tmp3;
    cin >> tmp2 >> tmp3;
    for (int i = 0; i < 10; i++) {
      tmp1.name[i] = tmp2[i];
    }
    tmp1.time = tmp3;
    l.push_back(tmp1);
  }
  int res = 0;
  while (!l.empty()) {
    if (l.begin()->time <= q) {
      res += l.begin()->time;
      cout << l.begin()->name << " " << res << endl;
      l.pop_front();
    } else {
      res += q;
      l.begin()->time -= q;
      l.push_back(*l.begin());
      l.pop_front();
    }
  }

  return 0;
}

Error: -11

Fixed submission:

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

struct pro {
  char *name;
  int time;
};

int main(int argc, char **argv) {

  list<pro> l;
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    pro tmp;
    cin >> tmp.name >> tmp.time;
    l.push_back(tmp);
  }

  int res = 0;
  while (!l.empty()) {
    if (l.begin()->time <= 100) {
      res += l.begin()->time;
      l.pop_front();
    } else {
      res += 100;
      l.begin()->time -= 100;
      l.push_back(*l.begin());
      l.pop_front();
    }
  }

  cout << res;

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

#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#define LEN 300005
using namespace std;

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

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

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

P dequeue() { return Q[head]; }

int main(int argc, char *argv[]) {
  int i, q;

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

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

  int elaps = 0;
  P u;
  head = 0, tail = n;
  while (head != tail) {
    u = Q[head++];
    if (u.time > q) {
      u.time -= q;
      Q[tail++] = u;
      elaps += q;
    } else {
      elaps = elaps + u.time;
      printf("%s %d\\n", u.name, elaps);
    }
  }

  return 0;
}


Error: 0

Fixed submission:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#define LEN 100005
using namespace std;

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

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

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

P dequeue() { return Q[head]; }

int main(int argc, char *argv[]) {
  int i, q;

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

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

  int elaps = 0;
  P u;
  head = 0, tail = n;
  while (head != tail) {
    u = Q[head++];
    if (u.time > q) {
      u.time -= q;
      Q[tail++] = u;
      elaps += q;
    } else {
      elaps = elaps + u.time;
      printf("%s %d\\n", u.name, elaps);
    }
  }

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

#include <iostream>
#include <queue>
/*que struct{
  string name;
  int time;
  }*/
int counter = 0;
using namespace std;
int main() {
  queue<string> Q1;
  queue<int> Q2;
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    string name;
    int time;
    cin >> name;
    cin >> time;
    Q1.push(name);
    Q2.push(time);
  }
  while ((!Q1.empty()) && (!Q2.empty())) {
    if (Q2.front() <= q) {
      cout << Q1.front() << " ";
      cout << Q2.front() + counter << endl;
      counter = counter + Q2.front();
      Q1.pop();
      Q2.pop();
    } else {
      Q1.push(Q1.front());
      Q1.pop();
      Q2.push(Q2.front() - q);
      Q2.pop();
      counter = counter + q;
    }
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <queue>
#include <string>
using namespace std;
struct Q {
  string name;
  int time;
};

int main() {
  int f, l, i, n, q, T = 0;
  cin >> n >> q;
  Q *que = new Q[n];
  Q *record = new Q[n];
  for (i = 0; i < n; i++)
    cin >> que[i].name >> que[i].time;
  f = 0;
  l = n - 1;
  i = 0;
  while (f != l) {
    if (que[f].time > q) {
      que[f].time = que[f].time - q;
      f++;
      if (f == n)
        f = 0;
      l++;
      if (l == n)
        l = 0;
      while (que[l].time == 0) {
        l++;
        if (l == n)
          l = 0;
      }
      T += q;
    } else if (que[f].time != 0) {
      T += que[f].time;
      que[f].time = 0;
      record[i].time = T;
      record[i].name = que[f].name;

      f++;
      if (f == n)
        f = 0;
      i++;
    } else {
      f++;
      if (f == n)
        f = 0;
    }
  }
  record[i].name = que[f].name;
  record[i].time = que[f].time + T;

  for (i = 0; i < n; i++) {
    cout << record[i].name << ' ' << record[i].time << endl;
  }
  // system("pause");
}
Problem p02264 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
#define MAX 100000

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

Queue Q[MAX];
int n; // nunber of queue
int t; // time for subtracting
int head, tail;

void enqueue(Queue q) {
  Q[tail] = q;
  tail = (tail + 1) % MAX;
}

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

int main() {
  int elapsed = 0;
  int c = 0;
  scanf("%d %d", &n, &t);

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

  // simulation starts from here
  head = 1;
  tail = n + 1;
  while (head != tail) {
    Queue tmp_q = dequeue(); // ??????Q????????????????????????
    c = std::min(tmp_q.time, t);
    tmp_q.time -= c;
    elapsed += c;
    if (tmp_q.time > 0)
      enqueue(tmp_q);
    else {
      printf("%s %d\\n", tmp_q.name, elapsed);
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
#define MAX 100000

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

Queue Q[MAX];
int n; // nunber of queue
int t; // time for subtracting
int head, tail;

void enqueue(int head, int tail, Queue q) {
  Q[tail] = q;
  tail = (tail + 1) % MAX;
}

Queue dequeue(int head) {
  Queue x = Q[head];
  head = (head + 1) % MAX;
  return x;
}

int main() {
  int elapsed = 0;
  scanf("%d %d", &n, &t);

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

  // simulation starts from here
  head = 1;
  tail = n + 1;
  while (true) {
    if (head == tail)
      break;
    Queue tmp_q = dequeue(head); // ??????Q????????????????????????
    // ???????????????t???????°?????????´???
    if (tmp_q.time < t) {
      elapsed += tmp_q.time;
      printf("%s %d\\n", tmp_q.name, elapsed);
    } else { // ???????????????t????????§????????´???
      tmp_q.time -= elapsed;
      elapsed += t;
      enqueue(head, tail, tmp_q);
    }
  }

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

#include <iostream>
#include <string>

using namespace std;

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

static const int MAX = 100000;
Process P[MAX];
int tail, head;

void enqueue(struct Process &p) {
  P[tail] = p;
  tail = (tail + 1) % MAX;
}

void dequeue(struct Process &p) {
  p = P[head];
  head = (head + 1) % MAX;
}

int main() {
  int n, q;

  cin >> n >> q;

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

  int count = 0;

  tail = n;

  struct Process p;

  while (head != tail) {
    dequeue(p);
    p.time -= q;
    if (p.time <= 0) {
      count += q + p.time;
      cout << p.name << " " << count << endl;
    } else {
      count += q;
      enqueue(p);
    }
  }
}

Error: 0

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

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

static const int MAX = 10000;
Process P[MAX];
int tail, head;

void enqueue(struct Process &p) {
  P[tail] = p;
  tail = (tail + 1) % MAX;
}

void dequeue(struct Process &p) {
  p = P[head];
  head = (head + 1) % MAX;
}

int main() {
  int n, q;

  cin >> n >> q;

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

  int count = 0;

  tail = n;

  struct Process p;

  while (head != tail) {
    dequeue(p);
    p.time -= q;
    if (p.time <= 0) {
      count += q + p.time;
      cout << p.name << " " << count << endl;
    } else {
      count += q;
      enqueue(p);
    }
  }
}
Problem p02264 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>

using namespace std;

struct Process {
  string name;
  int time;
};

int main() {
  int n, q;
  Process P[1000000];

  cin >> n >> q;

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

  int count = 0;
  int origin = n;

  for (int i = 0; i < n; i++) {
    P[i].time -= q;
    if (P[i].time <= 0) {
      count += q + P[i].time;
      cout << P[i].name << " " << count << endl;
    } else {
      n++;
      P[n - 1] = P[i];
      count += q;
    }
  }
}

Error: 0

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

struct Process {
  string name;
  int time;
};

int main() {
  int n, q;
  Process P[100000];

  cin >> n >> q;

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

  int count = 0;
  int origin = n;

  for (int i = 0; i < n; i++) {
    P[i].time -= q;
    if (P[i].time <= 0) {
      count += q + P[i].time;
      cout << P[i].name << " " << count << endl;
    } else {
      n++;
      P[n - 1] = P[i];
      count += q;
    }
  }
}
Problem p02264 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using std::cin;
using std::cout;

struct process {
  std::string name;
  unsigned time;
};

void execute(std::queue<process> &l, const unsigned q) {
  unsigned time_now = 0;

  while (!l.empty()) {
    process buf = l.front();
    l.pop();
    if (buf.time <= q) {
      time_now += buf.time;
      cout << buf.name << ' ' << time_now << '\\n';
    } else {
      buf.time -= q;
      time_now += q;
      l.push(buf);
    }
  }
}

int main() {
  std::queue<process> l;
  unsigned n, q;
  cin >> n >> q;
  for (unsigned i = 0; i < n; i++) {
    process buf;
    cin >> buf.name >> buf.time;
    l.push(buf);
  }

  execute(l, q);
}

Error: TLE

Fixed submission:

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

using std::cin;
using std::cout;

struct process {
  std::string name;
  unsigned time;
};

void execute(std::queue<process> &l, const unsigned q) {
  unsigned time_now = 0;
  process buf = l.front();
  l.pop();

  while (!l.empty()) {
    if (buf.time <= q) {
      time_now += buf.time;
      cout << buf.name << ' ' << time_now << '\\n';
    } else {
      buf.time -= q;
      time_now += q;
      l.push(buf);
    }
  }
}

int main() {
  std::queue<process> l;
  unsigned n, q;
  cin >> n >> q;
  for (unsigned i = 0; i < n; i++) {
    process buf;
    cin >> buf.name >> buf.time;
    l.push(buf);
  }

  execute(l, q);
}