rendered paste body//main question
//what happens next?
//-Departure
//-Arrival
//in.txt
//main.exe
//main.exe < in.txt puts the contents of in.txt into CIN
#include <iostream>
#include <queue>
using namespace std;
struct Customer
{
int arrival_time;
int items;
Customer(int a, int i)
{
arrival_time = a;
items = i;
}
Customer()
{
arrival_time = 0;
items = 0;
}
};
class Checkout
{
public:
void depart();
void arrive(Customer c);
bool empty() const;
int next_departure_time() const;
private:
queue<Customer> q_;
int departure_time_;
};
void Checkout::arrive(Customer c)
{
q_.push(c);
if(empty())
{
departure_time_ = c.arrival_time + c.items;
//print out arrival event
}
}
void Checkout::depart()
{
//assert queue isn't empty assert(!empty())
Customer c = q_.front();
q_.pop();
if(!q_.empty())
departure_time_ += q_.front().items;
//departure event
}
bool Checkout::empty() const
{
return q_.empty();
}
int Checkout::next_departure_time() const
{
//assert(!empty());
return departure_time_;
}
int main()
{
Checkout checkout;
int arrival = 0;
int items = 0;
while(cin >> arrival >> items)
Customer customer(arrival, items);
while(!checkout.empty() && checkout.next_departure_time() <= arrival)
//only makes sense as long as queue isn't empty
{
checkout.depart();
}
while(!checkout.empty())
{
checkout.arrive(customer));
}
while(!checkout.empty())
{
checkout.depart();
}
}