Problem p02264 (C++)

Buggy submission (status: Runtime Error):
//============================================================================
// Name        : AOJCpp.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <algorithm>
#include <iostream>
// #include <queue>
using namespace std;
static const int MAX = 100010;

class process {
private:
  string name;
  int time;

public:
  void setName(string s);
  void setTime(int t);
  string getName();
  int getTime();
};
void process::setName(string s) { name = s; }
void process::setTime(int i) { time = i; }
string process::getName() { return name; }
int process::getTime() { return time; }
class queue {
private:
  int head;
  int tail;
  process q[MAX];

public:
  void initialize();
  process front();
  void pop();
  void push(process p);
  bool empty();
};
void queue::initialize() {
  head = 0;
  tail = 0;
}
process queue::front() { return q[head]; }
void queue::pop() {
  if (head >= MAX) {
    head = 0;
  } else {
    head++;
  }
}
void queue::push(process p) {
  q[tail] = p;
  if (tail >= MAX) {
    tail = 0;
  } else {
    tail++;
  }
}
bool queue::empty() {
  if (head == tail) {
    return true;
  }
  return false;
}

int main() {

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

  queue que;
  que.initialize();
  string name;
  int time;
  for (int i = 0; i < n; i++) {
    cin >> name;
    cin >> time;
    process p;
    p.setName(name);
    p.setTime(time);
    que.push(p);
  }
  int total = 0;
  while (!que.empty()) {
    process p = que.front();
    que.pop();
    time = p.getTime();
    if (time > q) {
      p.setTime(time - q);
      total += q;
      que.push(p);
    } else {
      total += time;
      //			p.setTime(total);
      cout << p.getName() << " " << total << endl;
    }
  }
  return 0;
}


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

#include <algorithm>
#include <iostream>
// #include <queue>
using namespace std;
static const int MAX = 500000;

class process {
private:
  string name;
  int time;

public:
  void setName(string s);
  void setTime(int t);
  string getName();
  int getTime();
};
void process::setName(string s) { name = s; }
void process::setTime(int i) { time = i; }
string process::getName() { return name; }
int process::getTime() { return time; }
class queue {
private:
  int head;
  int tail;
  process q[MAX];

public:
  void initialize();
  process front();
  void pop();
  void push(process p);
  bool empty();
};
void queue::initialize() {
  head = 0;
  tail = 0;
}
process queue::front() { return q[head]; }
void queue::pop() {
  if (head >= MAX) {
    head = 0;
  } else {
    head++;
  }
}
void queue::push(process p) {
  q[tail] = p;
  if (tail >= MAX) {
    tail = 0;
  } else {
    tail++;
  }
}
bool queue::empty() {
  if (head == tail) {
    return true;
  }
  return false;
}

int main() {

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

  queue que;
  que.initialize();
  string name;
  int time;
  for (int i = 0; i < n; i++) {
    cin >> name;
    cin >> time;
    process p;
    p.setName(name);
    p.setTime(time);
    que.push(p);
  }
  int total = 0;
  while (!que.empty()) {
    process p = que.front();
    que.pop();
    time = p.getTime();
    if (time > q) {
      p.setTime(time - q);
      total += q;
      que.push(p);
    } else {
      total += time;
      //			p.setTime(total);
      cout << p.getName() << " " << total << endl;
    }
  }
  return 0;
}