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

//============================================================================
// Name        : Queue.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

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

int main() {
  string line;
  getline(cin, line);
  istringstream iss(line);

  int n, q;
  iss >> n >> q;

  vector<string> name_list;
  vector<int> time_list;
  for (int i = 0; i < n; i++) {
    getline(cin, line);
    istringstream iss(line);
    string input1;
    int time;
    iss >> input1 >> time;
    // cout << input1 << " " << time << "\\n";
    // int time;
    // time = stoi(input2);

    name_list.push_back(input1);
    time_list.push_back(time);
  }

  int total_time = 0;
  int n_jobs = n;
  int n_jobs_unfinished = 0;
  while (n_jobs > 0) {
    for (int i = 0; i < n_jobs; i++) {
      int residual = time_list.at(i) - q;
      if (residual > 0) {
        total_time = total_time + q;
        time_list.at(n_jobs_unfinished) = residual;
        name_list.at(n_jobs_unfinished) = name_list.at(i);
        n_jobs_unfinished = n_jobs_unfinished + 1;
      } else {
        total_time = total_time + time_list.at(i);
        cout << name_list.at(i) << " " << total_time << "\\n";
      }
    }

    n_jobs = n_jobs_unfinished;
    n_jobs_unfinished = 0;
  }
}


Error: TLE

Fixed submission:

//============================================================================
// Name        : Queue.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

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

int main() {
  string line;
  getline(cin, line);
  istringstream iss(line);

  int n, q;
  iss >> n >> q;

  vector<string> name_list;
  vector<int> time_list;
  for (int i = 0; i < n; i++) {
    getline(cin, line);
    istringstream iss(line);
    string input1;
    int time;
    iss >> input1 >> time;
    // cout << input1 << " " << time << "\\n";
    // int time;
    // time = stoi(input2);

    name_list.push_back(input1);
    time_list.push_back(time);
  }

  bool hasJobs = true;
  int total_time = 0;
  while (hasJobs) {
    hasJobs = false;
    for (int i = 0; i < n; i++) {
      if (time_list.at(i) == 0) {
        continue;
      }

      int residual = time_list.at(i) - q;
      if (residual > 0) {
        total_time = total_time + q;
        time_list.at(i) = residual;
        hasJobs = true;
      } else {
        total_time = total_time + time_list.at(i);
        time_list.at(i) = 0;
        cout << name_list.at(i) << " " << total_time << "\\n";
      }
    }
  }
}
Problem p02264 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <math.h>
#include <stdio.h>

using namespace std;

class PROCESS {
public:
  string name;
  int time;
};

PROCESS p[100000];
int headIndex = 0;
int lastIndex = 0;

void enqueue(PROCESS np) {
  p[lastIndex++] = np;
  if (lastIndex >= 100000)
    lastIndex = 0;
}

PROCESS dequeue() {
  PROCESS result = p[headIndex++];
  if (headIndex >= 100000)
    headIndex = 0;
  return result;
}

bool isEmpty() { return lastIndex == headIndex; }

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

  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

#include <iostream>
#include <math.h>
#include <stdio.h>

using namespace std;

class PROCESS {
public:
  string name;
  int time;
};

PROCESS p[100000];
int headIndex = 0;
int lastIndex = 0;

void enqueue(PROCESS np) {
  p[lastIndex++] = np;
  cout << 1;
  if (lastIndex >= 100000)
    lastIndex = 0;
}

PROCESS dequeue() {
  PROCESS result = p[headIndex--];
  if (headIndex >= 100000)
    headIndex = 0;
  return result;
}

bool isEmpty() { return lastIndex == headIndex; }

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

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

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

int main() {
  int n, q;
  cin >> n;
  cin >> q;
  // vector<int> tm[n];
  // vector<string> name[n];
  int tm[100000];
  string name[100000];
  int total = 0; //??????????????¨
  for (int i = 0; i < n; i++) {
    cin >> name[i];
    cin >> tm[i];
    total += tm[i];
  }
  int ptm = 0; // passed time
  while (1) {
    for (int i = 0; i < n; i++) {
      if (tm[i] == 0) {

      } else if (tm[i] <= q) {
        ptm += tm[i];
        tm[i] = 0;
        cout << name[i] << " " << ptm << endl;
        if (total == ptm)
          return 0;
      } else {
        ptm += q;
        tm[i] -= q;
      }
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, q;
  cin >> n;
  cin >> q;
  // vector<int> tm[n];
  // vector<string> name[n];
  int tm[100000];
  string name[100000];
  int total = 0; //??????????????¨
  for (int i = 0; i < n; i++) {
    cin >> name[i];
    cin >> tm[i];
    total += tm[i];
  }
  int ptm = 0; // passed time
  while (1) {
    for (int i = 0; i < n; i++) {
      if (tm[i] <= q) {
        if (tm[i] == 0)
          continue;
        ptm += tm[i];
        tm[i] = 0;
        cout << name[i] << " " << ptm << endl;
        if (total == ptm)
          return 0;
      } else {
        ptm += q;
        tm[i] -= q;
      }
    }
  }

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

#include <bits/stdc++.h>
#define LEN 100005

typedef struct pp {
  char name[100];
  int t;
} P;
P Q[LEN + 1];
int head, tail, n;
int min_(int a, int b) {
  if (a > b)
    return b;
  return a;
}
void enqueue(P x) {
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}
P dequeue() {
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;
}
int main() {
  int elaps = 0, 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 <bits/stdc++.h>
using namespace std;
#define maxn 100005
struct node {
  char name[10];
  int time;
} q[maxn];

int main() {
  int n, t;
  scanf("%d%d", &n, &t);
  for (int i = 1; i <= n; i++) {
    scanf("%s%d", q[i].name, &q[i].time);
  }
  int num = 0;
  long long tot = 0;
  for (int i = 1; num < n; i++) {
    if (i > n)
      i = 1;
    if (q[i].time <= 0)
      continue;
    int now = q[i].time;
    q[i].time -= t;
    if (q[i].time <= 0) {
      num++;
      tot += now;
      printf("%s %d\\n", q[i].name, tot);
      continue;
    }
    tot += t;
  }
  return 0;
}
Problem p02264 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int Q[100000];
int f = 0, e = 0, f2 = 0, e2 = 0;
int Q2[100000];

void input_time(int a) {
  Q[e] = a;
  e = (e + 1) % 100000;
}

int output_time() {
  int a = Q[f];
  f = (f + 1) % 100000;
  return a;
}

void input_name(int a) {
  Q2[e2] = a;
  e2 = (e2 + 1) % 100000;
}

int output_name() {
  int a = Q2[f2];
  f2 = (f2 + 1) % 100000;
  return a;
}

char name[100000][15];

int main() {
  int n, q;
  int time, count;

  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    cin >> name[i] >> time;
    input_time(time);
    input_name(i);
  }
  count = 0;
  while (1) {
    if ((time = output_time()) > q) {
      input_time(time - q);
      input_name(output_name());
      count += q;
    } else {
      count += time;

      cout << name[output_name()] << ' ' << count << endl;
    }
    if (e == f) {
      break;
    }
  }
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int Q[100000];
int f = 0, e = 0, f2 = 0, e2 = 0;
int Q2[100000];

void input_time(int a) {
  Q[e] = a;
  e = (e + 1) % 100000;
}

int output_time() {
  int a = Q[f];
  f = (f + 1) % 100000;
  return a;
}

void input_name(int a) {
  Q2[e2] = a;
  e2 = (e2 + 1) % 100000;
}

int output_name() {
  int a = Q2[f2];
  f2 = (f2 + 1) % 100000;
  return a;
}

char name[15][100000];

int main() {
  int n, q;
  int time, count;

  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    cin >> name[i] >> time;
    input_time(time);
    input_name(i);
  }
  count = 0;
  while (1) {
    if ((time = output_time()) > q) {
      input_time(time - q);
      input_name(output_name());
      count += q;
    } else {
      count += time;

      cout << name[output_name()] << ' ' << count << endl;
    }
    if (e == f) {
      break;
    }
  }
  return 0;
}
Problem p02264 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cassert>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

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

static const int MAX = 100000;
Process queue[MAX];
int qsize = 0, qhead = 0, qtail = 0;

// 結果自体は正しいが時間がかかりすぎる
int main(void) {

  int n, q;
  cin >> n >> q;

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

  int elapsed = 0;
  while (qhead != qtail) {
    Process p = queue[qhead++];
    qhead %= MAX;
    if (p.time - q <= 0) {
      elapsed += p.time;
      printf("%s %d\\n", p.name, elapsed);
    } else {
      elapsed += q;
      p.time -= q;
      queue[qtail++] = p;
      qtail %= MAX;
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cassert>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

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

Process queue[100000];
int qsize = 0;

static void rotate() {
  Process head = queue[0];
  for (int i = 1; i < qsize; ++i) {
    queue[i - 1] = queue[i];
  }
  queue[qsize - 1] = head;
}

int main(void) {

  int n, q;
  cin >> n >> q;

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

  int elapsed = 0;
  while (qsize != 0) {
    Process head = queue[0];
    rotate();
    --qsize;
    if (head.time - q <= 0) {
      elapsed += head.time;
      printf("%s %d\\n", head.name, elapsed);
    } else {
      elapsed += q;
      head.time -= q;
      queue[qsize++] = head;
    }
  }

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

#include <cstdlib>
#include <iostream>
#include <vector>
#define SIZE 100005
using namespace std;

struct Queue {
  int list[SIZE];
  int head, tail;
  void init() { head = tail = 0; }
  bool isEmpty() { return head == tail; }
  bool isFull() { return head == (tail + 1) % SIZE; }
  // int head(){ return list[head]; }
  // int tail(){ return list[tail]; }
  void enqueue(int x) {
    if (isFull()) {
      cout << "ERROR(Over flow)" << endl;
      exit(1);
    }
    list[tail] = x;
    tail++;
    tail %= SIZE;
  }
  int dequeue() {
    if (isEmpty()) {
      cout << "ERROR(Under flow)" << endl;
      exit(1);
    }
    int x = list[head];
    head++;
    head %= SIZE;
    return x;
  }
};
struct Process {
  string n;
  int t;
};
int main() {
  int n, q, idx, now = 0;
  vector<Process> p;
  Queue que;

  // input,initialize
  que.init();
  cin >> n >> q;
  p.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i].n >> p[i].t;
    que.enqueue(i);
  }

  // process
  while (!que.isEmpty()) {
    idx = que.dequeue();
    if (p[idx].t - q > 0) {
      p[idx].t -= q;
      now += q;
      que.enqueue(idx);
    } else {
      now += p[idx].t;
      p[idx].t = now;
      cout << p[idx].n << " " << p[idx].t << endl;
    }
  }
  return 0;
}


Error: 0

Fixed submission:

#include <cstdlib>
#include <iostream>
#include <vector>
#define SIZE 200
using namespace std;

struct Queue {
  int list[SIZE];
  int head, tail;
  void init() { head = tail = 0; }
  bool isEmpty() { return head == tail; }
  bool isFull() { return head == (tail + 1) % SIZE; }
  // int head(){ return list[head]; }
  // int tail(){ return list[tail]; }
  void enqueue(int x) {
    if (isFull()) {
      cout << "ERROR(Over flow)" << endl;
      exit(1);
    }
    list[tail] = x;
    tail++;
    tail %= SIZE;
  }
  int dequeue() {
    if (isEmpty()) {
      cout << "ERROR(Under flow)" << endl;
      exit(1);
    }
    int x = list[head];
    head++;
    head %= SIZE;
    return x;
  }
};
struct Process {
  string n;
  int t;
};
int main() {
  int n, q, idx, now = 0;
  vector<Process> p;
  Queue que;

  // input,initialize
  que.init();
  cin >> n >> q;
  p.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i].n >> p[i].t;
    que.enqueue(i);
  }

  // process
  while (!que.isEmpty()) {
    idx = que.dequeue();
    if (p[idx].t - q > 0) {
      p[idx].t -= q;
      now += q;
      que.enqueue(idx);
    } else {
      now += p[idx].t;
      p[idx].t = now;
      cout << p[idx].n << " " << p[idx].t << endl;
    }
  }
  return 0;
}
Problem p02264 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <cstring>
const int L = 100000;
int time[L];
char name[L][11];
int main() {
  int i, n, q, front = 0, back, size, t = 0;
  scanf("%d%d", &n, &q);
  back = n - 1;
  size = n;
  for (i = 0; i < n; i++) {
    scanf("%s %d", &name[i], &time[i]);
  }
  while (size > 0) {
    if (time[front] <= q) {
      t += time[front];
      printf("%s %d\\n", name[front], t);
      size--;
    } else {
      t += q;
      time[front] -= q;
      back = (back + 1) % L;
      time[back] = time[front];
      strcpy(name[back], name[front]);
    }
    front = (front + 1) % L;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <cstdio>
int time[100000];
char name[100000][11];
int main() {
  int i, n, q, top = 0, rest, t = 0;
  scanf("%d%d", &n, &q);
  rest = n;
  for (i = 0; i < n; i++) {
    scanf("%s %d", &name[i], &time[i]);
  }
  while (true) {
    if (time[top] <= q) {
      t += time[top];
      time[top] = 0;
      printf("%s %d\\n", name[top], t);
      rest -= 1;
      if (rest == 0)
        break;
      while (time[top] == 0)
        top = (top + 1) % n;
    } else {
      t += q;
      time[top] -= q;
      top = (top + 1) % n;
      while (time[top] == 0)
        top = (top + 1) % n;
    }
  }
  return 0;
}
Problem p02264 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int head, tail, n;
struct task {
  char name[100];
  int time;
} t, Q[1000000];
void enqueue(task x) {
  Q[tail] = x;
  tail++;
}
task dequeue() {
  task x = Q[head];
  head++;
  return x;
}
int main() {
  int q;
  cin >> n >> q;
  for (int i = 1; i <= n; i++)
    cin >> Q[i].name >> Q[i].time;
  head = 1;
  tail = n + 1;
  int sum = 0;
  while (head != tail) {
    t = dequeue();
    if (t.time > q) {
      sum += q;
      t.time -= q;
      enqueue(t);
    } else {
      sum += t.time;
      cout << t.name << ' ' << sum << endl;
    }
  }
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int head, tail, n;
struct task {
  char name[100];
  int time;
} t, Q[100005];
void enqueue(task x) {
  Q[tail] = x;
  tail++;
}
task dequeue() {
  task x = Q[head];
  head++;
  return x;
}
int main() {
  int q;
  cin >> n >> q;
  for (int i = 1; i <= n; i++)
    cin >> Q[i].name >> Q[i].time;
  head = 1;
  tail = n + 1;
  int sum = 0;
  while (head != tail) {
    t = dequeue();
    if (t.time > q) {
      sum += q;
      t.time -= q;
      enqueue(t);
    } else {
      sum += t.time;
      cout << t.name << ' ' << sum << endl;
    }
  }
  return 0;
}
Problem p02264 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

#define LEN 100005

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

p Q[LEN];

int head, tail;

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 n, q, els = 0, c;
  p temp;
  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) {
    temp = dequeue();
    c = min(temp.t, q);
    temp.t -= c;
    els += c;
    if (temp.t > 0) {
      enqueue(temp);
    } else {
      printf("%s %d\\n", temp.name, els);
    }
  }
  return 0;
}

Error: 0

Fixed submission:

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

struct Process {
  char name[101];
  int t;
};

struct Process Q[1001];
int n, head = 1, tail = 1;

void enqueue(struct Process x) {
  Q[tail] = x;
  if (tail == n)
    tail = 1;
  else
    tail++;
}

struct Process dequeue() {
  struct Process x;

  x = Q[head];

  if (head == n)
    head = 1;
  else
    head++;

  return x;
}

int main(void) {
  int i, q, cou = 0, time = 0;
  struct Process k;

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

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

  while (cou != n) {
    k = dequeue();

    if (k.t <= q) {
      time += k.t;
      printf("%s %d\\n", k.name, time);
      cou++;
    }

    else {
      time += q;
      k.t -= q;
      enqueue(k);
    }
  }

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

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  vector<string> name;
  vector<int> time;
  int n;
  cin >> n;
  int q;
  cin >> q;
  string damy1;
  int damy2;
  for (int i = 0; i < n; ++i) {
    cin >> damy1 >> damy2;
    name.push_back(damy1);
    time.push_back(damy2);
  }
  vector<string> nameans;
  vector<int> timeans;
  int max = 0;
  int he = 0;
  while (name.begin() + he != name.end()) {
    if (*(time.begin() + he) > q) {
      *(time.begin() + he) -= q;
      max += q;
      name.push_back(*(name.begin() + he));
      time.push_back(*(time.begin() + he));
    } else {
      max += *(time.begin() + he);
      nameans.push_back(*(name.begin() + he));
      timeans.push_back(max);
    }
    ++he;
  }
  for (int i = 0; nameans.begin() + i != nameans.end(); ++i) {
    cout << *(nameans.begin() + i) << " " << *(timeans.begin() + i) << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  vector<string> name;
  vector<int> time;
  int n;
  cin >> n;
  int q;
  cin >> q;
  string damy1;
  int damy2;
  for (int i = 0; i < n; ++i) {
    cin >> damy1 >> damy2;
    name.push_back(damy1);
    time.push_back(damy2);
  }
  vector<string> nameans;
  vector<int> timeans;
  int max = 0;
  while (!name.empty()) {
    if (*(time.begin()) > q) {
      *(time.begin()) -= q;
      max += q;
      name.push_back(*(name.begin()));
      time.push_back(*(time.begin()));
      name.erase(name.begin());
      time.erase(time.begin());
    } else {
      max += *(time.begin());
      nameans.push_back(*(name.begin()));
      timeans.push_back(max);
      name.erase(name.begin());
      time.erase(time.begin());
    }
  }
  for (int i = 0; nameans.begin() + i != nameans.end(); ++i) {
    cout << *(nameans.begin() + i) << " " << *(timeans.begin() + i) << endl;
  }
  return 0;
}
Problem p02264 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

pair<string, int> p[1000000];
pair<string, int> key;
int tail;
int head;

void push(string str, int n) {
  p[tail].first = str;
  p[tail].second = n;
  tail++;
}

void pop() {
  key = p[head];
  head++;
}

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

  for (int i = 0; i < n; i++) {
    cin >> p[i].first >> p[i].second;
  }
  tail = n;

  int cnt = 0;
  int sum = 0;
  while (cnt != n) {
    pop();
    string name = key.first;
    int time = key.second;
    // cout << name << " " << time << endl;
    if (time - q > 0) {
      sum += q;
      push(name, time - q);
    } else {
      cnt++;
      sum += time;
      cout << name << " " << sum << endl;
    }
  }
}

Error: MLE

Fixed submission:

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

pair<string, int> p[10000000];
pair<string, int> key;
int tail;
int head;

void push(string str, int n) {
  p[tail].first = str;
  p[tail].second = n;
  tail++;
}

void pop() {
  key = p[head];
  head++;
}

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

  for (int i = 0; i < n; i++) {
    cin >> p[i].first >> p[i].second;
  }
  tail = n;

  int cnt = 0;
  int sum = 0;
  while (cnt != n) {
    pop();
    string name = key.first;
    int time = key.second;
    // cout << name << " " << time << endl;
    if (time - q > 0) {
      sum += q;
      push(name, time - q);
    } else {
      cnt++;
      sum += time;
      cout << name << " " << sum << endl;
    }
  }
}
Problem p02264 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

int main() {
  int n, q, t = 0, min2;
  cin >> n >> q;
  string s;
  int t2;
  pair<string, int> tmp;
  queue<pair<string, int>> q1;
  for (int i = 0; i < n; i++) {
    cin >> s >> t2;
    q1.push(make_pair(s, t2));
  }
  while (q1.size() > 0) {
    tmp = q1.front();
    min2 = min(tmp.second, q);
    tmp.second -= min2;
    t += min2;
    if (tmp.second <= 0) {
      cout << tmp.first << " " << t << endl;
      q1.pop();
    } else {
      q1.push(tmp);
      q1.pop();
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

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

using namespace std;

int main() {
  int n, q, t = 0, tmp;
  cin >> n >> q;
  vector<string> s(n);
  int q2[n];
  queue<int> q1;
  for (int i = 0; i < n; i++) {
    cin >> s[i] >> q2[i];
    q1.push(q2[i]);
  }
  while (q1.size() > 0) {
    tmp = q1.front();
    q1.front() -= q;
    if (q1.front() <= 0) {
      t += tmp;
      cout << s[0] << " " << t << endl;
      q1.pop();
      s.erase(s.begin());
    } else {
      t += q;
      q1.push(q1.front());
      q1.pop();
      s.insert(s.end(), s[0]);
      s.erase(s.begin());
    }
  }
  return 0;
}