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

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

using namespace std;

struct Process {
  string name;
  long long time;
};

int main() {
  queue<Process> que;
  int n, q;
  cin >> n >> q;
  Process p[n], pp;
  for (int i = 0; i < n; i++) {
    cin >> p[i].name >> p[i].time;
    que.push(p[i]);
  }

  int timer = 0;
  while (!que.empty()) {
    pp = que.front();
    if (pp.time > q) {
      pp.time -= q;
      timer += q;
      que.pop();
      que.push(pp);
    } else {
      timer += pp.time;

      cout << que.front().name << " " << timer << endl;
      que.pop();
    }
  }

  return 0;
}


Error: -11

Fixed submission:

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

using namespace std;

struct Process {
  string name;
  long long time;
};

int main() {
  queue<Process> que;
  int n, q;
  Process p[n], pp;
  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    cin >> p[i].name >> p[i].time;
    que.push(p[i]);
  }

  int timer = 0;
  while (!que.empty()) {
    pp = que.front();
    if (pp.time > q) {
      pp.time -= q;
      timer += q;
      que.pop();
      que.push(pp);
    } else {
      timer += pp.time;
      cout << que.front().name << " " << timer << endl;
      que.pop();
    }
  }

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

#include <iostream>
#include <utility>
#include <vector>

using namespace std;

struct Process {
  string name;
  int time;

  Process() : name(""), time(0) {}
};

class Queue {
public:
  vector<Process *> q;
  int capacity;
  int begin;
  int end;
  int size;

  Queue(int cap) : q(cap, NULL), capacity(cap), begin(0), end(0), size(0) {}

  void enqueue(Process *p) {
    if (size + 1 <= capacity) {
      q[end] = p;
      ++end;
      end = end % capacity;
      ++size;
    }
  }

  Process *dequeue() {
    if (!empty()) {
      Process *p = q[begin];
      ++begin;
      begin = begin % capacity;
      --size;
      return p;
    } else {
      return NULL;
    }
  }

  bool empty() {
    if (size <= 0)
      return true;
    else
      return false;
  }
};

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

  vector<Process *> ps(N);
  Queue q(N);
  for (int i = 0; i < N; ++i) {
    Process *p = new Process;
    cin >> p->name >> p->time;
    q.enqueue(p);
    ps[i] = p;
  }

  int current = 0;
  while (!q.empty()) {
    Process *p = q.dequeue();
    if (p->time <= Q) {
      current += p->time;
      cout << p->name << ' ' << current << '\\n';
    } else {
      p->time -= Q;
      current += Q;
      q.enqueue(p);
    }
  }

  for (int i = 0; i < N; ++i)
    delete ps[i];
}


Error: TLE

Fixed submission:

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

using namespace std;

class Process {
private:
  string name;
  int time;

public:
  string get_name() { return this->name; }
  int get_time() { return this->time; }
  void set_name(string name) { this->name = name; }
  void set_time(int time) { this->time = time; }
};

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

  vector<Process> processes(n);
  for (int i = 0; i < n; ++i) {
    string name;
    int time;
    cin >> name >> time;

    processes[i].set_name(name);
    processes[i].set_time(time);
  }

  int i = 0;
  int current = 0;
  int finished = 0;
  while (true) {
    if (finished >= n)
      break;

    if (processes[i].get_time() == -1) {
      i = (i + 1 >= n) ? 0 : i + 1;
      continue;
    }

    if (processes[i].get_time() - q <= 0) {
      cout << processes[i].get_name() << ' '
           << current + processes[i].get_time() << '\\n';
      ++finished;

      current += processes[i].get_time();
      processes[i].set_time(-1);
    } else {
      processes[i].set_time(processes[i].get_time() - q);
      current += q;
    }

    i = (i + 1 >= n) ? 0 : i + 1;
  }
}
Problem p02264 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int q, n, i, time;
  string name;
  queue<pair<string, int>> Q;
  scanf("%d", &n);
  scanf("%d", &q);
  for (i = 0; i < n; i++) {
    cin >> name >> time;
    Q.push(make_pair(name, time));
  }
  pair<string, int> u;
  i = 0;
  while (!Q.empty()) {
    u = Q.front();
    Q.pop();
    if (u.second > q) {
      u.second -= q;
      Q.push(u);
      i += q;
    } else {
      i += u.second;
      cout << u.first << " ";
      // printf("%s ", u.first);
      printf("%d\\n", i);
    }
  }
  // printf("%lf\\n",(double)clock()/CLOCKS_PER_SEC);
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
#include <stdlib.h>
#define MAX 100001

typedef struct tq {
  char name[10];
  int time;
} s;
int top;
s S[MAX];

s pop() {
  int i, n = top;
  s t;
  t = S[0];
  for (i = 0; i < n; i++)
    S[i] = S[i + 1];
  top--;
  return t;
}

void push(s x) { S[top++] = x; }

int main() {
  int q, n, i, count;
  s x;
  top = 0;
  scanf("%d", &n);
  count = n;
  scanf("%d", &q);
  for (i = 0; i < n; i++) {
    scanf("%s", S[i].name);
    scanf("%d", &S[i].time);
    push(S[i]);
  }
  i = 0;
  while (S[0].time) {
    if (S[0].time > q) {
      S[0].time -= q;
      push(pop());
      i += q;
    } else {
      x = pop();
      i += x.time;
      printf("%s ", x.name);
      printf("%d\\n", i);
    }
  }
  return 0;
}
Problem p02264 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;

#define Rep(b, e, i) for (int i = b; i <= e; i++)
#define Repr(e, b, i) for (int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n - 1, i)
#define repr(n, i) Repr(n - 1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second

typedef pair<string, int> P;

void solve(void) {
  int N, Q;
  cin >> N >> Q;
  queue<P> q;
  rep(N, i) {
    string name;
    int t;
    cin >> name >> t;
    q.push(P(name, t));
  }
  int acct = 0;
  while (!q.empty()) {
    P p = q.front();
    q.pop();
    if (p.snd <= Q) {
      acct += p.snd;
      cout << p.fst << ' ' << acct << endl;
      continue;
    }
    p.second -= Q;
    acct += Q;
    q.push(p);
  }
}

int main(void) {
  solve();
  // cout << "yui(*-v・)yui" << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;

#define Rep(b, e, i) for (int i = b; i <= e; i++)
#define Repr(e, b, i) for (int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n - 1, i)
#define repr(n, i) Repr(n - 1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second

typedef pair<string, int> P;

void solve(void) {
  int N, Q;
  cin >> N >> Q;
  queue<P> q;
  rep(N, i) {
    string name;
    int t;
    cin >> name >> t;
    q.push(P(name, t));
  }
  int acct = 0;
  while (!q.empty()) {
    P &p = q.front();
    q.pop();
    if (p.snd <= Q) {
      acct += p.snd;
      cout << p.fst << ' ' << acct << endl;
      continue;
    }
    p.second -= Q;
    acct += Q;
    q.push(p);
  }
}

int main(void) {
  solve();
  // cout << "yui(*-v・)yui" << endl;
  return 0;
}
Problem p02264 (C++) — buggy submission, verdict: Time Limit Exceeded

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

struct foo {
  string s;
  int a;
};

int main() {
  int n, v, time = 0;
  foo f[100000];
  cin >> n >> v;
  for (int i = 0; i < n; i++) {
    cin >> f[i].s >> f[i].a;
  }
  int j = n, b = 0, flag = n;
  while (flag > 0) {
    f[b].a -= v, time += v;
    if (f[b].a > 0) {
      f[b + j] = f[b];
    } else {
      time += f[b].a, j--, flag--;
      cout << f[b].s << " " << time << endl;
    }
    b++;
    if (b > 99999)
      b = 0;
    if (j + b > 99999)
      j -= 100000;
    if (j + b < 0)
      j += 100000;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

struct foo {
  string s;
  int a;
};

int main() {
  int n, v, time = 0;
  foo f[100000];
  cin >> n >> v;
  for (int i = 0; i < n; i++) {
    cin >> f[i].s >> f[i].a;
  }
  int j = n;
  while (j > 0) {
    f[0].a -= v, time += v;
    if (f[0].a <= 0) {
      time += f[0].a;
      cout << f[0].s << " " << time << endl;
    }
    foo tmp = f[0];
    for (int i = 0; i < j - 1; i++) {
      f[i] = f[i + 1];
      f[i + 1] = tmp;
    }
    if (f[j - 1].a <= 0)
      j--;
  }

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

#include <algorithm>
#include <iostream>
#define N 100100
using namespace std;
typedef pair<string, int> P;
P queue[N];
int n, q, b, h, t, cnt;
string a;

void push(P x) {
  if (t + 1 == N)
    queue[t] = x, t = 0;
  else
    queue[t++] = x;
}

void pop() { h + 1 == N ? h = 0 : h++; }

bool empty() { return h == t; }

P front() { return queue[h]; }

int main() {
  cnt = h = 0, t = 0;
  cin >> n >> q;
  for (int i = 0; i < n; i++)
    cin >> a >> b, push(P(a, b));
  while (!empty()) {
    P t = front();
    pop();
    int tim = min(q, t.second);
    t.second -= tim;
    cnt += tim;
    if (!t.second)
      cout << t.first << ' ' << cnt << endl;
    else
      push(t);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#define N 100100
using namespace std;
typedef pair<string, int> P;
P queue[N];
int n, q, b, h, t, cnt;
string a;

void push(P x) {
  if (t + 1 == N)
    queue[t] = x, t = 0;
  else
    queue[t] = x, t++;
}

void pop() { h++; }

bool empty() { return h == t; }

P front() { return queue[h]; }

int main() {
  cnt = h = 0, t = 0;
  cin >> n >> q;
  for (int i = 0; i < n; i++)
    cin >> a >> b, push(P(a, b));
  while (!empty()) {
    P t = front();
    pop();
    int tim = min(q, t.second);
    t.second -= tim;
    cnt += tim;
    if (!t.second)
      cout << t.first << ' ' << cnt << endl;
    else
      push(t);
  }
  return 0;
}
Problem p02264 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <deque>
#include <iostream>
#include <map>
#include <string>
#include <vector>

#define fi first
#define se second

using namespace std;

template <class T> class myQueue {
  deque<T> v;

public:
  myQueue(){};
  void push(const T &n_) { v.push_back(n_); }
  void pop() { v.erase(v.begin()); }
  bool empty() { return v.empty(); }
  T front() { return v[0]; }
  T back() { return v[v.size() - 1]; }
  size_t size() { return v.size(); }
};

int main() {
  myQueue<pair<string, int>> mq;
  vector<pair<string, int>> vsi;
  int n, q, n2, time = 0;
  string s;
  pair<string, int> psi;
  cin >> n >> q;
  for (int i = 0; i < n; ++i) {
    cin >> s >> n2;
    mq.push(make_pair(s, n2));
  }
  while (!mq.empty()) {
    psi = mq.front();
    n2 = psi.se - q;
    if (n2 <= 0) {
      time += psi.se;
      vsi.push_back(make_pair(psi.fi, time));
    } else {
      time += q;
      psi.se = n2;
      mq.push(psi);
    }
    mq.pop();
  }
  for (auto n3 : vsi) {
    cout << n3.fi << " " << n3.se << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

#define fi first
#define se second

using namespace std;

template <class T> class myQueue {
  vector<T> v;

public:
  myQueue(){};
  void push(const T &n_) { v.push_back(n_); }
  void pop() { v.erase(v.begin()); }
  bool empty() { return v.empty(); }
  T front() { return v[0]; }
  T back() { return v[v.size() - 1]; }
  size_t size() { return v.size(); }
};

int main() {
  myQueue<pair<string, int>> mq;
  vector<pair<string, int>> vsi;
  int n, q, n2, time = 0;
  string s;
  pair<string, int> psi;
  cin >> n >> q;
  for (int i = 0; i < n; ++i) {
    cin >> s >> n2;
    mq.push(make_pair(s, n2));
  }
  while (!mq.empty()) {
    psi = mq.front();
    n2 = psi.se - q;
    if (n2 <= 0) {
      time += psi.se;
      vsi.push_back(make_pair(psi.fi, time));
    } else {
      time += q;
      psi.se = n2;
      mq.push(psi);
    }
    mq.pop();
  }
  for (auto n3 : vsi) {
    cout << n3.fi << " " << n3.se << endl;
  }

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

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

struct process {
  string name;
  int time;
};

struct finished {
  string name;
  int time;
};

queue<finished> RoundRobin(queue<process> X, int q) {
  queue<finished> Y;
  int totaltime = 0;
  while (X.size() > 0) {
    if (X.front().time <= q) {
      totaltime += X.front().time;
      finished output;
      output.name = X.front().name;
      output.time = totaltime;
      X.pop();
      Y.push(output);
    } else {
      totaltime += q;
      X.front().time -= q;
      X.push(X.front());
      X.pop();
    }
  }
  return Y;
}

int main() {
  int n, q;
  cin >> n;
  cin >> q;
  queue<process> Input;
  for (int i = 0; i < n; i++) {
    process imput;
    cin >> imput.name >> imput.time;
    Input.push(imput);
  }
  queue<finished> Output = RoundRobin(Input, q);
  for (int i = 0; i < n; i++) {
    cout << Output.front().name << " " << Output.front().time << endl;
    Output.pop();
  }
  return 0;
}

Error: TLE

Fixed submission:

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

struct process {
  string name;
  int time;
};

void RoundRobin(vector<process> &X, int q) {
  vector<process> Y;
  int totaltime = 0;
  while (!X.empty()) {
    int i = 0;
    while (i < X.size()) {
      if (X[i].time <= q) {
        totaltime += X[i].time;
        process finished;
        finished.name = X[i].name;
        finished.time = totaltime;
        Y.push_back(finished);
        X.erase(X.begin() + i);
      } else {
        totaltime += q;
        X[i].time -= q;
        i++;
      }
    }
  }
  for (int i = 0; i < Y.size(); i++) {
    cout << Y[i].name << " " << Y[i].time << endl;
  }
}

int main() {
  int n, q;
  cin >> n;
  cin >> q;
  vector<process> X;
  X.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> X[i].name >> X[i].time;
  }
  RoundRobin(X, q);
  return 0;
}
Problem p02264 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

typedef struct process {
  string name;
  int time;
} process_t;
int head = 0;
int tail = 0;
int t = 0;

vector<process_t> arr;
void enqueue(process_t p) {
  tail++;
  //        arr[tail] = arr[h];
  arr.push_back(p);
}

process_t dequeue() {
  process_t p = arr[head];
  //    arr.erase(arr.begin());
  head++;
  return p;
}

void print_arr(string name, int time) { cout << name << " " << time << endl; }

void solve(int q) {

  while (head <= tail) {
    process_t p = dequeue();
    if (p.time > q) {
      p.time = p.time - q;
      t += q;
      enqueue(p);
    } else {
      t += p.time;
      print_arr(p.name, t);
    }
    //    if (head>tail) {
    //      return;
    //}
    // solve(q);
  }
}

int main() {
  int N = 0;
  int q = 0;
  cin >> N;
  cin >> q;
  tail = N - 1;
  // process_t* arr = (process_t*)malloc(100 * sizeof(process_t));
  for (int i = 0; i < N; i++) {
    //	cin >> arr[i].name >> arr[i].time;
    process_t p = {};
    cin >> p.name;
    cin >> p.time;
    arr.push_back(p);
  }
  solve(q);
  return 0;
}

Error: 0

Fixed submission:

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

using namespace std;

typedef struct process {
  string name;
  long time;
} process_t;
long head = 0;
long tail = 0;
long t = 0;

vector<process_t> arr;
void enqueue(process_t p) {
  tail++;
  //        arr[tail] = arr[h];
  arr.push_back(p);
}

process_t dequeue() {
  process_t p = arr[head];
  //    arr.erase(arr.begin());
  head++;
  return p;
}

void print_arr(string name, long time) { cout << name << " " << time << endl; }

void solve(long q) {
  process_t p = dequeue();

  if (p.time > q) {
    p.time = p.time - q;
    t += q;
    enqueue(p);
  } else {
    t += p.time;
    print_arr(p.name, t);
  }
  if (head > tail) {
    return;
  }
  solve(q);
}

int main() {
  long N = 0;
  long q = 0;
  cin >> N;
  cin >> q;
  tail = N - 1;
  // process_t* arr = (process_t*)malloc(100 * sizeof(process_t));
  for (long i = 0; i < N; i++) {
    //	cin >> arr[i].name >> arr[i].time;
    process_t p = {};
    cin >> p.name;
    cin >> p.time;
    arr.push_back(p);
  }
  solve(q);
  return 0;
}
Problem p02264 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int i, n, q, x, sumq = 0;
  string ss;
  queue<string> qt1;
  queue<int> qt2;

  cin >> n >> q;

  for (i = 0; i < n; i++) {
    cin >> ss >> x;
    qt1.push(ss);
    qt2.push(x);
  }

  while (!qt1.empty()) {
    if ((qt2.front() - q) > 0) {
      x = qt2.front() - q;
      qt2.pop();
      qt2.push(x);
      ss = qt1.front();
      qt1.pop();
      qt1.push(ss);
      sumq = sumq + q;
    }
    if ((qt2.front() - q) <= 0) {
      sumq = sumq + qt2.front();
      cout << qt1.front() << ' ' << sumq << endl;
      qt1.pop();
      qt2.pop();
    }
  }

  return 0;
}

Error: 0

Fixed submission:

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

using namespace std;

typedef struct process {
  string name;
  int time;
} process_t;
int head = 0;
int tail = 0;
int t = 0;

vector<process_t> arr;
void enqueue(process_t p) {
  //    tail++;
  //        arr[tail] = arr[h];
  arr.push_back(p);
}

process_t dequeue() {
  process_t p = arr[head];
  //    arr.erase(arr.begin());
  head++;
  return p;
}

void print_arr(string name, int time) { cout << name << " " << time << endl; }

void solve(int q) {
  process_t p = dequeue();

  if (p.time > q) {
    p.time = p.time - q;
    t += q;
    enqueue(p);
  } else {
    t += p.time;
    print_arr(p.name, t);
  }
  if (head == arr.size()) {
    return;
  }
  solve(q);
}

int main() {
  int N = 0;
  int q = 0;
  cin >> N;
  cin >> q;
  tail = N - 1;
  // process_t* arr = (process_t*)malloc(100 * sizeof(process_t));
  for (int i = 0; i < N; i++) {
    //	cin >> arr[i].name >> arr[i].time;
    process_t p = {};
    cin >> p.name;
    cin >> p.time;
    arr.push_back(p);
  }
  solve(q);
  return 0;
}
Problem p02264 (C++) — buggy submission, verdict: Runtime Error

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

struct Process {
  string name;
  int time;
};

int const MAX = 1000000;
int head;
int tail;
Process Q[MAX];

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

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

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

void enqueue(Process x) {
  if (isFull()) {
    cout << "エラー(オーバーフロー)" << endl;
    return;
  }
  Q[tail] = x;
  if (head + 1 == MAX) {
    head = 0;
  } else {
    tail++;
  }
}

Process denqueue() {
  if (isEmpty()) {
    cout << "エラー(アンダーフロー)" << endl;
  }
  Process x = Q[head];
  if (head + 1 == MAX) {
    head = 0;
  } else {
    head++;
  }
  return x;
}

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


Error: 0

Fixed submission:

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

struct Process {
  string name;
  int time;
};

int const MAX = 100000;
int head;
int tail;
Process Q[MAX];

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

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

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

void enqueue(Process x) {
  if (isFull()) {
    cout << "エラー(オーバーフロー)" << endl;
    return;
  }
  Q[tail] = x;
  if (head + 1 == MAX) {
    head = 0;
  } else {
    tail++;
  }
}

Process denqueue() {
  if (isEmpty()) {
    cout << "エラー(アンダーフロー)" << endl;
  }
  Process x = Q[head];
  if (head + 1 == MAX) {
    head = 0;
  } else {
    head++;
  }
  return x;
}

int main() {
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n; ++i) {
    string name;
    int time;
    cin >> name >> time;
    enqueue(Process{name, time});
  }
  int elapsed_time = 0;
  while (!isEmpty()) {
    Process p = denqueue();
    if (p.time > q) {
      elapsed_time += q;
      p.time -= q;
      enqueue(p);
    } else {
      elapsed_time += p.time;
      cout << p.name << " " << elapsed_time << endl;
    }
  }
}
Problem p02264 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
queue<pair<string, int>> Q;
pair<string, int> P;

int main() {
  int n, q, time;
  string name;
  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    cin >> name >> time;
    P = make_pair(name, time);
    Q.push(P);
  }
  int sum = 0;
  while (!Q.empty()) {
    P = Q.front();
    time = P.second;
    if (time > q) {
      P.second -= q;
      sum += q;
      Q.push(P);
      Q.pop();
    } else {
      sum += time;
      cout << P.first << " " << sum << endl;
      Q.pop();
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <queue>
#include <stdio.h>
using namespace std;

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

void change(process p0[], int l, int q);
void del(process p0[], int &l);

struct process p0[100001];
struct process p1[100001];

int main() {
  int i, n, q, l, temp, mark = 0, count = 0;

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

  l = n;
  while (!Q.empty()) {
    if (Q.front() > q) {
      temp = Q.front();
      Q.pop();
      temp -= q;
      Q.push(temp);
      count += q;
      change(p0, l, q);
    } else {
      temp = Q.front();
      Q.pop();
      p1[mark] = p0[0];
      p1[mark++].time = p0[0].time + count;
      del(p0, l);
      count += temp;
    }
  }

  for (i = 0; i < n; i++)
    printf("%s %d\\n", p1[i].name, p1[i].time);

  return 0;
}

void change(process p0[], int n, int q) {
  int i;
  struct process t;
  p0[0].time -= q;
  t = p0[0];

  for (i = 0; i < n - 1; i++)
    p0[i] = p0[i + 1];
  p0[n - 1] = t;

  return;
}

void del(process p0[], int &n) {
  int i;
  struct process t;

  for (i = 0; i < n - 1; i++)
    p0[i] = p0[i + 1];
  n -= 1;

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

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
struct node {
  char str[11];
  int t;
};
node a[100001];
int main() {
  int n, q;
  while (scanf("%d%d", &n, &q) != EOF) {
    queue<node> Q;
    for (int i = 0; i < n; i++) {
      scanf("%s", a[i].str);
      scanf("%d", &a[i].t);
      Q.push(a[i]);
    }
    int sum = 0;
    while (!Q.empty()) {
      if (Q.front().t <= q) {
        sum += Q.front().t;
        printf("%s %d\\n", Q.front().str, sum);
        Q.pop();
      } else {
        Q.front().t -= q;
        sum += q;
        Q.push(Q.front());
        Q.pop();
      }
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
struct node {
  char name[15];
  int time;
};
queue<node> que;
int q_time = 0;
int main() {
  int n, q;
  scanf("%d&d", &n, &q);
  for (int i = 1; i <= n; ++i) {
    node tmp;
    scanf("%s%d", tmp.name, &tmp.time);
    que.push(tmp);
  }
  while (!que.empty()) {
    node k = que.front();
    que.pop();
    if (k.time > q) {
      k.time -= q;
      que.push(k);
      q_time += q;
    } else {
      q_time += k.time;
      printf("%s %d\\n", k.name, q_time);
    }
  }
  return 0;
}