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

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

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

const long LEN = 510029;

class queue {
  process data[LEN];
  int head, tail;

public:
  queue() : head(0), tail(0) {}

  void enqueue(const process &p) {
    data[tail + 1] = p;
    tail = (tail + 1) % LEN;
  }
  process &dequeue() {
    head = (head + 1) % LEN;
    return data[head];
  }

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

int main() {
  queue q;

  int n;
  short quan;
  cin >> n >> quan;

  process p;

  int passTime = 0;

  for (int i = 0; !q.isEmpty() || i < n; i++) {

    if (i < n) {
      scanf("%s %d", &p.name, &p.time);
    } else
      p = q.dequeue();

    if (p.time - quan <= 0) {
      passTime += p.time;
      printf("%s %d\\n", p.name, passTime);

    } else {
      passTime += quan;
      p.time -= quan;
      q.enqueue(p);
    }
  }
}

Error: TLE

Fixed submission:

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

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

const long LEN = 100000;

class queue {
  process data[LEN];
  int head, tail;

public:
  queue() : head(0), tail(0) {} //
  void enqueue(const process &);
  process &dequeue();
  bool isEmpty();
  bool isFull();
};

void queue::enqueue(const process &p) {
  if (isFull()) {
    cout << "full!" << endl;
    exit(1);
  }

  data[tail + 1] = p;
  tail = (tail + 1) % LEN;
}
process &queue::dequeue() {
  if (isEmpty()) {
    cout << "empty!" << endl;
    exit(1);
  }

  head = (head + 1) % LEN;
  return data[head];
}
bool queue::isEmpty() { return head == tail; }
bool queue::isFull() { return (tail + 1) % LEN == head; }

int main() {
  queue q;

  int n, quan;
  cin >> n >> quan;

  process p;

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

    scanf("%s %d", &p.name, &p.time);
    q.enqueue(p);
  }

  int passTime = 0;

  while (!q.isEmpty()) {
    process t = q.dequeue();
    if (t.time - quan <= 0) {
      passTime += t.time;
      printf("%s %d\\n", t.name, passTime);
    } else {
      passTime += quan;
      t.time -= quan;
      q.enqueue(t);
    }
  }
}
Problem p02264 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
const int LEN = 100000; //??????????????§??????
struct pp {
  char name[10];
  int time;
} P[LEN];
int head, tail, n;
void enqueue(struct pp x) //??\\????????°
{
  P[tail] = x;             //?°?x?????\\??°????°?
  tail = (tail + 1) % LEN; //??¨?????????????????????????????????head=(tail + 1)
                           //% LEN??¶??´???????????????
}
struct pp dequeue() //???????????°
{
  struct pp x = P[head]; //?°?head??????????????´????´?????????\\??????x
  head = (head + 1) % LEN;
  return x; //????????????????´?
}
int min(int a, int b) //??????a???b?????´????°???????
{
  return a < b ? a : b;
}
int main() {
  int alltime = 0; //?´??????¶??´  ?±???¨????????????????§????
  int n, q;        // n??¨???????????°???q??¨?????¶??´????????§?°?
  struct pp u;
  cin >> n >> q;
  //?°?????????????????????°?????????
  for (int i = 0; i < n; i++) {
    cin >> P[i].name >> P[i].time;
  }
  head = 0;
  tail = n;
  //?¨??????¶??´????????¬???
  while (head != tail) {
    u = dequeue(); //?????´????´???????
    int c =
        min(q, u.time); //????????¶??´????????§?°??????\\????????????????????¶??´
    u.time = u.time - q; //????????????????????????????????¶??´
    alltime = alltime + c;
    if (u.time > 0)
      enqueue(u); //??¶??´????????¬????????\\??°????°?
    else {
      cout << u.name << " " << alltime << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
const int LEN = 100000; //????????????????????§??????
struct pp {
  char name[10];
  int time;
} P[LEN];
int head, tail, n;
void enqueue(struct pp x) //??\\????????°
{
  P[tail] = x;     //?°?x?????\\??°????°?
  tail = tail + 1; //??¨?????????????????????????????????head=(tail + 1) %
                   //LEN??¶??´???????????????
}
struct pp dequeue() //???????????°
{
  struct pp x = P[head]; //?°?head??????????????´????´?????????\\??????x
  head = head + 1;
  return x; //????????????????´?
}
int min(int a, int b) //??????a???b?????´????°???????
{
  return a < b ? a : b;
}
int main() {
  int alltime = 0; //?´??????¶??´  ?±???¨????????????????§????
  int n, q;        // n??¨???????????°???q??¨?????¶??´????????§?°?
  struct pp u;
  cin >> n >> q;
  //?°?????????????????????°?????????
  for (int i = 0; i < n; i++) {
    cin >> P[i].name >> P[i].time;
  }
  head = 0;
  tail = n;
  //?¨??????¶??´????????¬???
  while (head != tail) {
    u = dequeue(); //?????´????´???????
    int c =
        min(q, u.time); //????????¶??´????????§?°??????\\????????????????????¶??´
    u.time = u.time - q; //????????????????????????????????¶??´
    alltime = alltime + c;
    if (u.time > 0)
      enqueue(u); //??¶??´????????¬????????\\??°????°?
    else {
      cout << u.name << " " << alltime << endl;
    }
  }
  return 0;
}
Problem p02264 (C++) — buggy submission, verdict: Runtime Error

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

int main(void) {
  int Q[1000000];
  int tail = 0, head = 0;

  pair<string, int> p[100001];
  int n, q, su = 0;
  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    cin >> p[i].first >> p[i].second;
    Q[tail] = i;
    tail++;
    su += p[i].second;
  }
  int sum = 0, k;
  while (su != sum) {
    int d = Q[head];
    head++;
    if (p[d].second > q) {
      p[d].second = p[d].second - q;
      Q[tail] = d;
      tail++;
      sum += q;
    } else {
      sum += p[d].second;
      cout << p[d].first << " " << sum << endl;
    }
  }
  return 0;
}


Error: 0

Fixed submission:

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

int main(void) {
  int Q[100001];
  int tail = 0, head = 0;

  pair<string, int> p[100001];
  int n, q, su = 0;
  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    cin >> p[i].first >> p[i].second;
    Q[tail] = i;
    tail++;
    su += p[i].second;
  }
  int sum = 0, k;
  while (su != sum) {
    int d = Q[head];
    head++;
    if (p[d].second > q) {
      p[d].second = p[d].second - q;
      Q[tail] = d;
      tail++;
      sum += q;
    } else {
      sum += p[d].second;
      cout << p[d].first << " " << sum << endl;
    }
  }
  return 0;
}
Problem p02264 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, q, y, t = 0;
  string x;
  cin >> n >> q;
  queue<pair<string, int>> a;
  pair<string, int> b;
  for (int i = 0; i < n; i++) {
    cin >> b.first >> b.second;
    a.push(b);
  }
  while (!a.empty()) {
    b = a.front();
    if (b.second <= q) {
      t += b.second;
      cout << b.first << ' ' << t << endl;
      a.pop();
    } else {
      b.second = b.second - q;
      a.pop();
      a.push(b);
      t += q;
    }
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, q, y;
  string x;
  cin >> n >> q;
  queue<pair<string, int>> a;
  pair<string, int> b;
  for (int i = 0; i < n; i++) {
    cin >> b.first >> b.second;
    a.push(b);
  }
  while (!a.empty()) {
    b = a.front();
    if (b.second <= q) {
      cout << b.first << ' ' << b.second << endl;
    } else {
      b.first = b.first;
      b.second = b.second - q;
    }
  }
}
Problem p02264 (C++) — buggy submission, verdict: Time Limit Exceeded

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

struct task {
  int idx;
  int next;
  int prev;
  std::string name;
  int time;
};

int main() {
  int n, q;
  int time = 0;
  int done = 0;
  task queue[100000];

  // input
  std::ios::sync_with_stdio(false);
  std::cin >> n >> q;

  // make queue
  queue[0].prev = n - 1;
  for (int i = 0; i < n; i++) {
    queue[i].idx = i;
    if (i != 0)
      queue[i].prev = i - 1;
    std::cin >> queue[i].name >> queue[i].time;
    if (i == n - 1)
      queue[i].next = 0;
    else
      queue[i].next = i + 1;
  }

  int i = 0;
  while (done < n) {
    if (queue[i].time > q) {
      time += q;
      queue[i].time -= q;
    } else {
      done++;
      time += queue[i].time;
      queue[queue[i].prev].next = queue[i].next;
      queue[queue[i].next].prev = queue[i].prev;
      std::cout << queue[i].name << " " << time << std::endl;
    }
    i = queue[i].next;
  }
}


Error: TLE

Fixed submission:

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

struct task {
  std::string name;
  int time;
};

int main() {
  std::vector<task> queue;
  int n, q;
  int time = 0;

  // input
  // std::ios::sync_with_stdio(false);
  std::cin >> n >> q;
  for (int i = 0; i < n; i++) {
    task temp;
    std::cin >> temp.name >> temp.time;
    queue.push_back(temp);
  }

  auto i = queue.begin();
  while (!queue.empty()) {
    if (i->time > q) {
      i->time -= q;
      time += q;
      ++i;
    } else {
      time += i->time;
      std::cout << i->name << " " << time << std::endl;
      i = queue.erase(i);
    }

    if (i == queue.end())
      i = queue.begin();
  }
}
Problem p02264 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
#include <queue>
using namespace std;
typedef struct pp {
  char name[100];
  int t;
} P;
queue<P> m;
int main() {
  int i, n, q, ans = 0;
  P u;
  cin >> n >> q;
  for (i = 0; i < n; i++) {
    cin >> u.name >> u.t;
    m.push(u);
  }
  while (!m.empty()) {
    u = m.front();
    if (q >= u.t) {
      ans += u.t;
      m.pop();
      cout << u.name << " " << ans << endl;
    } else {
      ans += q;
      u.t -= q;
      m.push(u);
      m.pop();
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cassert>
#include <stdio.h>
#include <string.h>
#define LEN 10000

struct P {
  char name[1000];
  int t;
};

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

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

P dequeue() {
  P x = Q[head];
  if (head == LEN)
    head = 1;
  else
    head++;
  return x;
}
int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }

void trace() {
  int i;
  //  printf("(%d-%d)\\n", head, tail);
  if (head <= tail) {
    for (i = head; i < tail; i++) {
      printf("%s[%d] - ", Q[i].name, Q[i].t);
    }
    printf("\\n");
  } else {
    for (i = head; i <= LEN; i++) {
      printf("%s[%d] - ", Q[i].name, Q[i].t);
    }
    for (i = 1; i < tail; i++) {
      printf("%s[%d] - ", Q[i].name, Q[i].t);
    }
    printf("\\n");
  }
}

int main() {
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);
  assert(1 <= n && n <= 1000);
  assert(1 <= q && q <= 1000);
  for (i = 1; i <= n; i++) {
    scanf("%s", Q[i].name);
    assert(strlen(Q[i].name) <= 10);
    scanf("%d", &Q[i].t);
    assert(1 <= Q[i].t && Q[i].t <= 1000);
  }
  head = 1;
  tail = n + 1;

  while (head != tail) {
    //    trace();
    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: Time Limit Exceeded

#include <cstdio>
#include <cstring>

#define MAX 100005

struct Data {
  char name[11];
  int num;
};

Data d[MAX];
int head, tail, n;

void enqueue(Data t) {
  d[tail] = t;
  tail = (tail + 1) % MAX;
}

Data dequeue() {
  int tmp = head;
  head = (head + 1) % MAX;
  return d[tmp];
}

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

int main() {

  int time, now = 0;
  scanf("%d %d", &n, &time);

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

  head = 0;
  tail = n;

  while (head != tail) {
    Data tmp = dequeue();
    if (time < tmp.num) {
      tmp.num -= time;
      now += time;
      enqueue(tmp);
    } else {
      now += tmp.num;
      printf("%s %d\\n", tmp.name, now);
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>

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

  int time[100000];
  char name[10][11];
  for (int i = 0; i < n; i++) {
    scanf("%s %d", &name[i], &time[i]);
  }

  int now = 0;
  while (n) {
    if (time[0] - q <= 0) {
      now += time[0];
      printf("%s %d\\n", name[0], now);
      for (int i = 1; i < n; i++) {
        time[i - 1] = time[i];
        strcpy(name[i - 1], name[i]);
      }
      n--;

    } else {
      now += q;
      time[0] -= q;
      int temp_int = time[0];
      char temp_str[11];
      strcpy(temp_str, name[0]);
      for (int i = 1; i < n; i++) {
        time[i - 1] = time[i];
        strcpy(name[i - 1], name[i]);
      }
      time[n - 1] = temp_int;
      strcpy(name[n - 1], temp_str);
    }
  }
  return 0;
}
Problem p02264 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
struct pro {
  string x;
  int y;
};
int i = 0, teil;
int main() {
  int n, time = 0, rim;
  cin >> n >> rim;
  teil = n;
  pro aho[n + 1] = {};
  for (int i = 0; i < n; i++) {
    cin >> aho[i].x >> aho[i].y;
  }
  int i = 0;
  while (i != teil) {
    if (aho[i].y > rim) {
      time += rim;
      aho[i].y -= rim;
      aho[teil] = aho[i];
      if (teil == n) {
        teil = 0;
        i++;
      } else if (i == n) {
        teil++;
        i = 0;
      } else {
        i++;
        teil++;
      }

    } else if (aho[i].y <= rim) {
      time += aho[i].y;
      aho[i].y = time;
      cout << aho[i].x << " " << aho[i].y << endl;
      if (i == n) {
        i = 0;
      } else {
        i++;
      }
    }
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
struct pro {
  string x;
  int y;
};
int main() {
  int n, time = 0, rim;
  cin >> n >> rim;
  pro aho[n];
  pro v;
  for (int i = 0; i < n; i++) {
    cin >> aho[i].x >> aho[i].y;
  }
  int i = 0;
  while (i < n) {
    if (aho[i].y > rim && i < n) {
      time += rim;
      aho[i].y -= rim;
      pro v;
      v = aho[i];
      for (int j = i; j < n - 1; j++) {
        aho[j] = aho[j + 1];
      }
      aho[n - 1] = v;
    } else if (aho[i].y <= rim) {
      time += aho[i].y;
      aho[i].y = time;
      i++;
    }
  }
  for (int i = 0; i < n; i++) {
    cout << aho[i].x << " " << aho[i].y << endl;
  }
}
Problem p02264 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
#include <vector>
#define MAX 1000000
using namespace std;

struct pp {
  int t;
  string s;
};

class queue {
public:
  int head;
  int tail;
  vector<pp> v;
  queue();
  void enqueue(pp x);
  pp dequeue();
  bool isEmpty();
};

queue::queue() {
  head = 0;
  tail = 0;
  v.resize(MAX);
}

void queue::enqueue(pp x) {
  v[tail].t = x.t;
  v[tail].s = x.s;
  tail++;
}

pp queue::dequeue() {
  head++;
  return v[head - 1];
}

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

int main() {
  int n;
  cin >> n;
  int q;
  cin >> q;
  queue q1;
  for (int i = 0; i < n; i++) {
    pp p;
    cin >> p.s >> p.t;
    // cout << p.s << endl;
    q1.enqueue(p);
  }

  int passtime = 0;
  vector<pp> v;
  while (!q1.isEmpty()) {
    pp ptmp = q1.dequeue();
    // cout << ptmp.s << endl;
    if (ptmp.t > q) {
      passtime += q;
      ptmp.t -= q;
      q1.enqueue(ptmp);
    } else {
      passtime += ptmp.t;
      ptmp.t = passtime;
      v.push_back(ptmp);
    }
  }
  for (int i = 0; i < v.size(); i++) {
    cout << v[i].s << " " << v[i].t << endl;
  }
}

Error: 0

Fixed submission:

#include <iostream>
#include <string>
#include <vector>
#define MAX 100000
using namespace std;

struct pp {
  int t;
  string s;
};

class queue {
public:
  int head;
  int tail;
  vector<pp> v;
  queue();
  void enqueue(pp x);
  pp dequeue();
  bool isEmpty();
};

queue::queue() {
  head = 0;
  tail = 0;
  v.resize(MAX);
}

void queue::enqueue(pp x) {
  v[tail].t = x.t;
  v[tail].s = x.s;
  tail++;
}

pp queue::dequeue() {
  head++;
  return v[head - 1];
}

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

int main() {
  int n;
  cin >> n;
  int q;
  cin >> q;
  queue q1;
  for (int i = 0; i < n; i++) {
    pp p;
    cin >> p.s >> p.t;
    // cout << p.s << endl;
    q1.enqueue(p);
  }

  int passtime = 0;
  vector<pp> v;
  while (!q1.isEmpty()) {
    pp ptmp = q1.dequeue();
    // cout << ptmp.s << endl;
    if (ptmp.t > q) {
      passtime += q;
      ptmp.t -= q;
      q1.enqueue(ptmp);
    } else {
      passtime += ptmp.t;
      ptmp.t = passtime;
      v.push_back(ptmp);
    }
  }
  for (int i = 0; i < v.size(); i++) {
    cout << v[i].s << " " << v[i].t << endl;
  }
}
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);
    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 10005

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;
}
Problem p02264 (C++) — buggy submission, verdict: Runtime Error

#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--)

#include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct {
  char name[20];
  int time;
} QUEUE;

int main(int argc, const char *argv[]) {

  // Input
  int t_slice, num;
  int size;
  int front = 0;
  int rear = 0;
  ;
  int ctime = 0;

  scanf("%d %d", &num, &t_slice);

  size = 2 * num;

  QUEUE q[size];

  for (rear = 0; rear < num; rear++) {
    scanf("%s %d", q[rear].name, &(q[rear].time));
  }

  while (front != rear) {

    if (q[front].time > t_slice) {
      q[front].time -= t_slice;
      q[rear] = q[front];
      rear = (rear + 1) % size;
      ctime += t_slice;
    } else {
      printf("%s %d\\n", q[front].name, ctime + q[front].time);
      ctime += q[front].time;
    }
    front = (front + 1) % size;
  }

  return 0;
}

Error: 0

Fixed submission:

#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--)

#include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define SIZE (20000)

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

typedef struct {
  int start_p;
  int end_p;
  Process *q;
} Queue;

Process *pop(Queue *que) {

  if (que->start_p == que->end_p)
    return NULL;

  if (que->start_p + 1 >= SIZE) {
    que->start_p = 0;
  }
  return &(que->q[que->start_p++]);
}

void push(Queue *que, Process *p) {

  if (que->end_p + 1 >= SIZE) {
    que->end_p = 0;
  }
  que->q[que->end_p] = *p;
  que->end_p = (que->end_p + 1) % SIZE;
}

int main(int argc, const char *argv[]) {

  // Input
  int t_slice, p_num;
  int i;
  int ctime = 0;
  Queue que;
  Process *p;

  scanf("%d %d", &p_num, &t_slice);

  que.start_p = 0;
  que.end_p = p_num;
  que.q = (Process *)malloc(sizeof(Process) * SIZE);

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

  while ((p = pop(&que)) != NULL) {

    if (p->time > t_slice) {
      p->time -= t_slice;
      push(&que, p);
      ctime += t_slice;
    } else {
      printf("%s %d\\n", p->name, ctime + p->time);
      ctime += p->time;
    }
  }

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define pb(n) push_back(n)
#define mp(n, m) make_pair(n, m)
#define fi first
#define se second
#define all(r) (r).begin(), (r).end()

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define rep(i, n) REP(i, 0, n)
#define REPE(i, s, e) for (int i = s; i > e; i--)
#define repe(i, n) REPE(i, n, -1)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<vi> vvi;

const int IMAX = ((1 << 30) - 1) * 2 + 1;
const int INF = 100000000;
const double EPS = 1e-10;
// int mod=1000000007

int main() {
  int n, q;
  cin >> n >> q;
  queue<pair<int, string>> que;
  string s;
  int m;
  rep(i, n) {
    cin >> s >> m;
    que.push(pair<int, string>(m, s));
  }
  int t = 0;
  pair<int, string> p;
  while (!que.empty()) {
    p = que.front();
    que.pop();
    if (p.fi - q > 0) {
      que.push(pair<int, string>(p.fi - q, p.se));
      t += q;
    } else {
      t += p.fi;
      cout << p.se << " " << t << endl;
    }
  }
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define pb(n) push_back(n)
#define mp(n, m) make_pair(n, m)
#define fi first
#define se second
#define all(r) (r).begin(), (r).end()

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define rep(i, n) REP(i, 0, n)
#define REPE(i, s, e) for (int i = s; i > e; i--)
#define repe(i, n) REPE(i, n, -1)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<vi> vvi;

const int IMAX = ((1 << 30) - 1) * 2 + 1;
const int INF = 100000000;
const double EPS = 1e-10;
// int mod=1000000007

int main() {
  int n, q;
  cin >> n >> q;
  queue<pair<int, string>> que;
  string s;
  int m;
  rep(i, n) {
    cin >> s >> m;
    que.push(pair<int, string>(m, s));
  }
  int t = 0;
  pair<int, string> p;
  while (!que.empty()) {
    p = que.front();
    if (p.fi - q > 0) {
      que.push(pair<int, string>(p.fi - q, p.se));
      t += q;
      cout << p.se << " " << t << endl;

    } else
      t += p.fi;
  }
}