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

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

int main(void) {
  stack<int> st;
  string s;
  while (cin >> s) {
    char c = s[0];
    if (isdigit(c)) {
      st.push(stoi(s));
    } else {
      int b = st.top();
      st.pop();
      int a = st.top();
      st.pop();
      int ret = 0;
      if (c == '+')
        ret = a + b;
      else if (c == '-')
        ret = a - b;
      else if (c == '*')
        ret = a * b;
      st.push(ret);
    }
    cin.ignore();
  }
  cout << st.top() << endl;
  return 0;
}

Error: 0
3


Fixed submission:

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

int main(void) {
  stack<int> st;

  string s;
  while (cin >> s) {
    char c = s[0];
    if (isdigit(c)) {
      st.push(stoi(s));
    } else {
      int b = st.top();
      st.pop();
      int a = st.top();
      st.pop();
      int ret = 0;
      if (c == '+')
        ret = a + b;
      else if (c == '-')
        ret = a - b;
      else if (c == '*')
        ret = a * b;
      st.push(ret);
      cerr << ret << endl;
    }
  }
  cout << st.top() << endl;
  return 0;
}
Problem p02264 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#define INT_MAX 2147483647

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

class Queue {
private:
  Process Table[1000000];
  int head;
  int top;

public:
  Queue() {
    head = 0;
    top = 0;
  };
  void Enqueue(Process P) { Table[top++] = P; };
  Process Dequeue() { return Table[head++]; };
  bool isEmpty() { return head == top; };
  void show() {
    std::cout << "head : " << head << '\\n';
    std::cout << "top : " << top << '\\n';
  };
};

int main(int argc, char const *argv[]) {
  int n;
  int q;
  int cumtime = 0;
  Process P;
  Queue queue = Queue();
  std::cin >> n >> q;

  for (size_t i = 0; i < n; i++) {
    std::cin >> P.name;
    std::cin >> P.time;
    queue.Enqueue(P);
  }

  while (!queue.isEmpty()) {
    P = queue.Dequeue();
    P.time -= q;
    if (P.time > 0) {
      queue.Enqueue(P);
      cumtime += q;
    } else {
      cumtime += (q + P.time);
      std::cout << P.name << ' ' << cumtime << '\\n';
    }
  }

  return 0;
}


Error: -11

Fixed submission:

#include <iostream>
#define INT_MAX 2147483647

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

class Queue {
private:
  Process Table[INT_MAX];
  int head;
  int top;

public:
  Queue() {
    head = 0;
    top = 0;
  };
  void Enqueue(Process P) { Table[top++] = P; };
  Process Dequeue() { return Table[head++]; };
  bool isEmpty() { return head == top; };
  void show() {
    std::cout << "head : " << head << '\\n';
    std::cout << "top : " << top << '\\n';
  };
};

int main(int argc, char const *argv[]) {
  int n;
  int q;
  int cumtime = 0;
  Process P;
  Queue queue = Queue();
  std::cin >> n >> q;

  for (size_t i = 0; i < n; i++) {
    std::cin >> P.name;
    std::cin >> P.time;
    queue.Enqueue(P);
  }

  while (!queue.isEmpty()) {
    P = queue.Dequeue();
    P.time -= q;
    if (P.time > 0) {
      queue.Enqueue(P);
      cumtime += q;
    } else {
      cumtime += (q + P.time);
      std::cout << P.name << ' ' << cumtime << '\\n';
    }
  }

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

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

struct proc {
  std::string name;
  int time;
  proc(std::string s, int i) {
    name = s;
    time = i;
  };
};

int min(int a, int b) { return a < b ? a : b; }

int main() {

  int n;
  std::cin >> n;
  int q;
  std::cin >> q;
  std::queue<proc> p;

  for (int i = 0; i < n; i++) {
    std::string name;
    int time;
    std::cin >> name >> time;
    p.push(proc(name, time));
  }

  int elapsed_t = 0;
  while (!p.empty()) {
    int t = min(p.front().time, q);
    p.front().time -= t;
    elapsed_t += t;
    if (p.front().time != 0)
      p.push(p.front());
    else
      std::cout << p.front().name << " " << elapsed_t << std::endl;
    p.pop();
  }
  return 0;
}

Error: TLE

Fixed submission:

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

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

int main() {

  int n;
  std::cin >> n;
  int q;
  std::cin >> q;
  std::vector<proc> p;
  p.resize(n);

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

  int t = 0;
  int cnt = 0;
  while (cnt != n) {

    for (std::vector<proc>::iterator i = p.begin(); i != p.end() && cnt != n;
         ++i) {

      if (i->time == 0)
        ; // just ignore
      else if (i->time > q) {
        i->time -= q;
        t += q;
      } else {
        t += i->time;
        i->time = 0;

        std::cout << i->name << " " << t << std::endl;
        cnt++;
        if (i != p.begin()) {
          i = p.erase(i);
          if (!p.empty())
            i--;
        }
      }
    }
  }
}
Problem p02264 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  string name;
  int i, n, q, time, elapsedt = 0;
  list<pair<string, int>> que, ans;
  list<pair<string, int>>::iterator it;
  cin >> n >> q;
  for (i = 0; i < n; i++) {
    cin >> name >> time;
    que.push_back(make_pair(name, time));
  }
  it = que.begin();
  while (!que.empty()) {
    if ((*it).second <= q) {
      elapsedt += (*it).second;
      ans.push_back(make_pair((*it).first, elapsedt));
      it = que.erase(it);
    } else {
      elapsedt += q;
      (*it).second -= q;
      it++;
    }
    if (it == que.end())
      it = que.begin();
  }
  for (it = ans.begin(); it != ans.end(); it++) {
    cout << (*it).first << " " << (*it).second << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  string name;
  int i, n, q, time, elapsedt = 0;
  vector<pair<string, int>> que, ans;
  cin >> n >> q;
  for (i = 0; i < n; i++) {
    cin >> name >> time;
    que.push_back(make_pair(name, time));
  }
  while (ans.size() < n) {
    for (i = 0; i < n; i++) {
      if (que[i].second <= 0) {
        continue;
      } else if (que[i].second <= q) {
        elapsedt += que[i].second;
        que[i].second = 0;
        ans.push_back(make_pair(que[i].first, elapsedt));
      } else {
        elapsedt += q;
        que[i].second -= q;
      }
    }
  }
  for (i = 0; i < n; i++) {
    cout << ans[i].first << " " << ans[i].second << endl;
  }
  return 0;
}
Problem p02264 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
const int J = 100005;
struct pp {
  char name[110];
  int t;
};
struct pailie {
  pp a[J];
  int head, tail;
  bool isfull() {
    if ((tail + 1) % J == head)
      return 1;
    return 0;
  }
  bool isempty() {
    if (head == tail)
      return 1;
    return 0;
  }
  void push(pp x) {
    if (!isfull()) {
      a[tail % J] = x;
      tail++;
    }
  }
  pp pop() {
    if (!isempty()) {
      pp m = a[head % J];
      head++;
      return m;
    }
  }
} q;
int main() {
  int n, m;
  pp p;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%s%d", p.name, &p.t);
    q.push(p);
  }
  int mn = 0;
  while (!q.isempty()) {
    pp p1;
    p1 = q.pop();
    if (p1.t <= m) {
      mn += p1.t;
      printf("%s %d\\n", p1.name, mn);
    } else {
      mn += m;
      p1.t -= m;
      q.push(p1);
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>
#include <string.h>
int main() {
  struct aa {
    char s[20];
    int f;
  };
  int n, m;
  struct aa p[308];
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%s %d", p[i].s, &p[i].f);
  }
  int u = 0;
  while (n) {
    if (p[0].f > m) {
      u += m;
      p[0].f -= m;
      struct aa o = p[0];
      for (int i = 0; i <= n - 2; i++) {
        p[i] = p[i + 1];
      }
      p[n - 1] = o;
    } else {
      u += p[0].f;
      p[0].f = 0;
      printf("%s %d\\n", p[0].s, u);
      for (int i = 0; i <= n - 2; i++) {
        p[i] = p[i + 1];
      }
      n--;
    }
  }
  return 0;
}
Problem p02264 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
#include <utility>

using namespace std;

class mqueue {
private:
  pair<string, int> a[100005];
  int size, f, b;

public:
  mqueue() {
    size = 100005;
    f = 0;
    b = 0;
  }
  bool empty() { return f == b; }
  void push(pair<string, int> e) {
    if ((f + 1) % size == b)
      throw "Error: full";
    a[f] = e;
    f++;
    if (f == size)
      f = 0;
  }
  pair<string, int> front() { return a[b]; }
  void pop() {
    if (!empty()) {
      b++;
      if (b == size)
        b = 0;
    } else
      throw "Error: empty";
  }
};

int main(void) {
  int n, q;
  mqueue m;
  cin >> n >> q;
  string name;
  int time;
  for (int i = 0; i < n; i++) {
    cin >> name >> time;
    m.push(make_pair(name, time));
  }
  int elapsed = 0;
  while (!m.empty()) {
    auto c = m.front();
    m.pop();
    c.second -= q;
    elapsed += q;
    if (c.second > 0)
      m.push(c);
    else {
      elapsed += c.second;
      cout << c.first << " " << elapsed << endl;
    }
  }
}


Error: 0

Fixed submission:

#include <iostream>
#include <string>
#include <utility>

using namespace std;

class mqueue {
private:
  pair<string, int> a[100005];
  int size, f, b;

public:
  mqueue() {
    size = 100005;
    f = 0;
    b = 0;
  }
  bool empty() { return f == b; }
  void push(pair<string, int> e) {
    if (f + 1 == b)
      throw "Error: full";
    a[f] = e;
    f++;
    if (f == size)
      f = 0;
  }
  pair<string, int> front() { return a[b]; }
  void pop() {
    if (!empty()) {
      b++;
      if (b == size)
        f = 0;
    } else
      throw "Error: empty";
  }
};

int main(void) {
  int n, q;
  mqueue m;
  cin >> n >> q;
  string name;
  int time;
  for (int i = 0; i < n; i++) {
    cin >> name >> time;
    m.push(make_pair(name, time));
  }
  int elapsed = 0;
  while (!m.empty()) {
    auto c = m.front();
    m.pop();
    c.second -= q;
    elapsed += q;
    if (c.second > 0)
      m.push(c);
    else {
      elapsed += c.second;
      cout << c.first << " " << elapsed << endl;
    }
  }
}
Problem p02264 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <memory>

template <typename T> class queue {
public:
  explicit queue(int size)
      : size_(size), head_(0), tail_(0), data_(std::make_unique<T[]>(size)) {}

  void enqueue(T x) {
    data_[tail_] = x;
    tail_ = (tail_ + 1) % size_;
  }

  T dequeue() {
    auto x = data_[head_];
    head_ = (head_ + 1) % size_;
    return x;
  }

  bool is_empty() { return head_ == tail_; }

  bool is_full() { return tail_ == size_; }

private:
  int size_;
  int head_;
  int tail_;
  std::unique_ptr<T[]> data_;
};

struct proc {
  proc() : name_(""), value_(0) {}

  std::string name_;
  int value_;
};

int main() {
  int n, q;
  std::cin >> n >> q;
  queue<proc> proc_q(n + 1);
  for (int i = 0; i < n; ++i) {
    proc p;
    std::cin >> p.name_ >> p.value_;
    proc_q.enqueue(p);
  }

  int elapsed_time = 0;
  while (true) {
    auto p = proc_q.dequeue();
    if (p.value_ > 0) {
      elapsed_time += std::min(p.value_, q);
      p.value_ = std::max(p.value_ - q, 0);
      if (p.value_ == 0) {
        std::cout << p.name_ << " " << elapsed_time << std::endl;
      } else {
        proc_q.enqueue(p);
      }
    }

    if (proc_q.is_empty()) {
      break;
    }
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <memory>

template <typename T> class queue {
public:
  explicit queue(int size)
      : size_(size), head_(0), tail_(0), data_(std::make_unique<T[]>(size)) {}

  void enqueue(T x) {
    data_[tail_] = x;
    tail_ = (tail_ + 1) % size_;
  }

  T dequeue() {
    auto x = data_[head_];
    head_ = (head_ + 1) % size_;
  }

  bool is_empty() { return head_ == tail_; }

  bool is_full() { return tail_ == 1; }

private:
  int size_;
  int head_;
  int tail_;
  std::unique_ptr<T[]> data_;
};

struct proc {
  proc() : name_(""), value_(0) {}

  std::string name_;
  int value_;
};

int main() {
  int n, q;
  std::cin >> n >> q;
  proc p[n];
  for (int i = 0; i < n; ++i) {
    std::cin >> p[i].name_ >> p[i].value_;
  }

  int elapsed_time = 0;
  int finished_count = 0;
  while (true) {
    for (int i = 0; i < n; ++i) {
      if (p[i].value_ > 0) {
        elapsed_time += std::min(p[i].value_, q);
        p[i].value_ = std::max(p[i].value_ - q, 0);
        if (p[i].value_ == 0) {
          std::cout << p[i].name_ << " " << elapsed_time << std::endl;
          finished_count++;
        }
      }
    }

    if (finished_count == n) {
      break;
    }
  }

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

#include <iostream>
#include <string>

using namespace std;

class Process {
private:
  string name;
  int time;

public:
  Process() = default;
  Process(string name, int time) {
    this->name = name;
    this->time = time;
  }
  string getName() { return this->name; }
  int getTime() { return this->time; }
  void setTime(int time) { this->time = time; }
};

int pos_min = 0;
int pos_max = 0;
Process queue[1000000];

void enqueue(Process &process) {
  queue[pos_max] = process;
  pos_max++;
}

Process dequeue() {
  Process process = queue[pos_min];
  pos_min++;
  return process;
}

bool isEmpty() { return pos_min == pos_max; }

int main() {

  int num, quantum;
  scanf("%d %d", &num, &quantum);

  for (int i = 0; i < num; i++) {
    char name[100];
    int time;
    scanf("%s %d", name, &time);
    Process process(name, time);
    enqueue(process);
  }

  int cost = 0;
  while (true) {
    Process process = dequeue();
    if (process.getTime() > quantum) {
      cost += quantum;
      process.setTime(process.getTime() - quantum);
      enqueue(process);
    } else if (process.getTime() <= quantum) {
      cost += process.getTime();
      printf("%s %d\\n", process.getName().c_str(), cost);
      if (isEmpty()) {
        break;
      }
    }
  }

  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

class Process {
private:
  string name;
  int time;

public:
  Process() = default;
  Process(string name, int time) {
    this->name = name;
    this->time = time;
  }
  string getName() { return this->name; }
  int getTime() { return this->time; }
  void setTime(int time) { this->time = time; }
};

int pos_min = 0;
int pos_max = 0;
Process queue[100000];

void enqueue(Process &process) {
  queue[pos_max] = process;
  pos_max++;
}

Process dequeue() {
  Process process = queue[pos_min];
  pos_min++;
  return process;
}

bool isEmpty() { return pos_min == pos_max; }

int main() {

  int num, quantum;
  scanf("%d %d", &num, &quantum);

  for (int i = 0; i < num; i++) {
    char name[100];
    int time;
    scanf("%s %d", name, &time);
    Process process(name, time);
    enqueue(process);
  }

  int cost = 0;
  while (true) {
    Process process = dequeue();
    if (process.getTime() > quantum) {
      cost += quantum;
      process.setTime(process.getTime() - quantum);
      enqueue(process);
    } else if (process.getTime() <= quantum) {
      cost += process.getTime();
      printf("%s %d\\n", process.getName().c_str(), cost);
      if (isEmpty()) {
        break;
      }
    }
  }

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

#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
#define MAX 200000

int tail = 0;

int head = 0;

typedef struct _queue {
  char name[10];
  int time;
} queuecell;

queuecell queue[MAX];

void enqueue(char *name, int time) {
  tail++;
  strcpy(queue[tail].name, name);
  queue[tail].time = time;
  head++;
}

queuecell dequeue() {
  queuecell cell;

  strcpy(cell.name, queue[head].name);
  cell.time = queue[head].time;
  head++;

  return cell;
}

int main() {
  int n, maxtime;
  int sumtime = 0;
  cin >> n;
  cin >> maxtime;
  queuecell cell;

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

  while (tail >= head) {
    if (queue[head].time > maxtime) {
      sumtime += maxtime;
      enqueue(queue[head].name, queue[head].time - maxtime);
    } else {
      cell = dequeue();
      sumtime += cell.time;
      printf("%s %d\\n", cell.name, sumtime);
    }
  }
}


Error: 0

Fixed submission:

#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
#define MAX 100000

int tail = 0;

int head = 0;

typedef struct _queue {
  char name[10];
  int time;
} queuecell;

queuecell queue[MAX];

void enqueue(char *name, int time) {
  tail++;
  strcpy(queue[tail].name, name);
  queue[tail].time = time;
  head++;
}

queuecell dequeue() {
  queuecell cell;

  strcpy(cell.name, queue[head].name);
  cell.time = queue[head].time;
  head++;

  return cell;
}

int main() {
  int n, maxtime;
  int sumtime = 0;
  cin >> n;
  cin >> maxtime;
  queuecell cell;

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

  while (tail >= head) {
    if (queue[head].time > maxtime) {
      sumtime += maxtime;
      enqueue(queue[head].name, queue[head].time - maxtime);
    } else {
      cell = dequeue();
      sumtime += cell.time;
      printf("%s %d\\n", cell.name, sumtime);
    }
  }
}
Problem p02264 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

struct Data {
  string s;
  int t;
};

class Queue {
private:
  int head, tail;
  enum { MAX = 100000 };
  Data deq[MAX + 1];

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

  void push(Data p) {
    deq[tail++] = p;
    if (tail == MAX + 1)
      tail = 0;
  }

  Data pop() {
    Data ret = deq[head++];
    if (head == MAX + 1)
      head = 0;
    return ret;
  }

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

int main() {

  int N, Q;
  cin >> N >> Q;

  Queue que;

  for (int i = 0; i < N; i++) {
    string s;
    int t;
    cin >> s >> t;
    que.push((Data){s, t});
  }

  int elasped = 0;

  while (!que.empty()) {
    Data dat = que.pop();
    if (dat.t > Q) {
      dat.t -= Q;
      elasped += Q;
      que.push(dat);
    } else {
      elasped += dat.t;
      cout << dat.s << ' ' << elasped << endl;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

struct Data {
  string s;
  int t;
};

class Queue {
private:
  int head, tail;
  enum { MAX = 100000 };
  Data deq[MAX];

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

  void push(Data p) {
    deq[tail++] = p;
    if (tail == MAX + 1)
      tail = 0;
  }

  Data pop() {
    Data ret = deq[head++];
    return ret;
  }

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

int main() {

  int N, Q;
  cin >> N >> Q;

  Queue que;

  for (int i = 0; i < N; i++) {
    string s;
    int t;
    cin >> s >> t;
    que.push((Data){s, t});
  }

  int elasped = 0;

  while (!que.empty()) {
    Data dat = que.pop();
    if (dat.t > Q) {
      dat.t -= Q;
      elasped += Q;
      que.push(dat);
    } else {
      elasped += dat.t;
      cout << dat.s << ' ' << elasped << 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;
};

void Calculate(queue<Process> p, int q) {
  int time = 0;

  while (1) {

    Process temp;
    temp = p.front();

    if (temp.time > q) {
      temp.time -= q;
      p.push(temp);
      time += q;
      p.pop();
    } else {
      time += temp.time;
      cout << temp.name << " " << time << endl;
      p.pop();
    }
    if (p.size() == 0)
      break;
  }
  return;
}

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

Error: TLE

Fixed submission:

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

using namespace std;

struct Process {
  string name;
  int time;
};

void Calculate(vector<Process> p, int q) {
  int time = 0;

  while (1) {
    if (p[0].time > q) {
      p[0].time -= q;
      p.push_back(p[0]);
      time += q;
      vector<Process>::iterator it; //????´??????????
      it = p.begin();
      p.erase(it);
    } else {
      time += p[0].time;
      cout << p[0].name << " " << time << endl;
      vector<Process>::iterator it; //????´??????????
      it = p.begin();
      p.erase(it);
    }
    if (p.size() == 0)
      break;
  }
  return;
}

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

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

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

class myqueue {
public:
  int size;
  int begin;
  int end;
  Process v[111111];
  myqueue() {
    size = 111111;
    begin = 0;
    end = 0; //[begin, end)
  }

  void push(Process a) {
    v[end] = a;
    end = (end + 1) % size;
  }
  Process front() { return v[begin]; }
  void pop() { begin = (begin + 1) % size; }
  bool isEmpty() { return begin == end; }
  void pr() {
    for (int i = begin; i < end; i++) {
      cout << v[i].name << " ";
    }
    cout << endl;
  }
};

int main(void) {
  int n, q;
  myqueue que;
  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    Process tmp;
    cin >> tmp.name >> tmp.time;
    que.push(tmp);
  }
  int t = 0;
  while (!que.isEmpty()) {
    Process a = que.front();
    que.pop();
    if (a.time > q) {
      a.time -= q;
      que.push(a);
      t += q;
    } else {
      t += a.time;
      cout << a.name << " " << t << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

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

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

class myqueue {
public:
  int size;
  int begin;
  int end;
  Process v[111111];
  myqueue() {
    size = 111111;
    begin = 0;
    end = 0; //[begin, end)
  }

  void push(Process a) {
    v[end] = a;
    end = (end + 1) % size;
  }
  Process front() { return v[begin]; }
  void pop() { begin++; }
  bool isEmpty() { return begin == end; }
  void pr() {
    for (int i = begin; i < end; i++) {
      cout << v[i].name << " ";
    }
    cout << endl;
  }
};

int main(void) {
  int n, q;
  myqueue que;
  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    Process tmp;
    cin >> tmp.name >> tmp.time;
    que.push(tmp);
  }
  int t = 0;
  while (!que.isEmpty()) {
    Process a = que.front();
    que.pop();
    if (a.time > q) {
      a.time -= q;
      que.push(a);
      t += q;
    } else {
      t += a.time;
      cout << a.name << " " << t << endl;
    }
  }
  return 0;
}