class MaxQueue {
private Queue q;
private Deque dq;
public MaxQueue() {
q = new LinkedList();
dq = new LinkedList();
}
public int max_value() {
return dq.isEmpty() ? -1 : (int)dq.getFirst();
}
public void push_back(int value) {
q.offer(value);
while (!dq.isEmpty() && (int)dq.getLast() < value) {
dq.pollLast();
}
dq.addLast(value);
}
public int pop_front() {
if (!dq.isEmpty() && (int)dq.getFirst() == (int)q.element()) {
dq.pollFirst();
}
return q.isEmpty() ? -1 : (int)q.poll();
}
}
/**
* Your MaxQueue object will be instantiated and called as such:
* MaxQueue obj = new MaxQueue();
* int param_1 = obj.max_value();
* obj.push_back(value);
* int param_3 = obj.pop_front();
*/