#include<bits/stdc++.h>
using namespace std;
class Navigate {
public:
int currentFloor;
int sourceFloor;
int destinationFloor;
int timeStamp;
Navigate () {
currentFloor = 0;
};
Navigate ( int currentFloor, int intputSourceFloor, int inputDestinationFloor, int inputTimestamp) :
currentFloor(currentFloor) ,sourceFloor(intputSourceFloor) , destinationFloor(inputDestinationFloor) ,timeStamp(inputTimestamp)
{};
};
class QueueSystem {
public:
set<Navigate> liftQueue;
set<pair<int,int> > nextInstuctionFloor;
int getCurrentFloor () {
if( !liftQueue.empty() ) {
auto firstInstruction = *liftQueue.begin();
return firstInstruction.currentFloor;
}
return 0;
}
int getLatestTimeStamp () {
if( !liftQueue.empty() ) {
auto firstInstruction = *liftQueue.rbegin();
return firstInstruction.timeStamp;
}
return 0;
}
} queueSystem;
int getNextFloor() {
if ( !queueSystem.liftQueue.empty() ) {
auto nextDirectionInfo = *queueSystem.liftQueue.begin();
queueSystem.liftQueue.erase(nextDirectionInfo);
auto next = *queueSystem.nextInstuctionFloor.begin();
// If movement direction is same
if ( !( (next.first < next.second ) ^ (nextDirectionInfo.sourceFloor < nextDirectionInfo.destinationFloor) ) ) {
// If current nextDirectionInfo [ 2 -> 4 ] ( source & destinationFloor)
// But there is some movement [3 - > 5 ] then 3 is return after reaching 2
if ( next.first > nextDirectionInfo.sourceFloor && nextDirectionInfo.destinationFloor < next.second ){
queueSystem.nextInstuctionFloor.erase(next);
return next.first;
}
}
return nextDirectionInfo.destinationFloor;
}
return 0;
}
bool operator < ( const Navigate &firstNavigation , const Navigate &secondNavigation) {
return firstNavigation.timeStamp < secondNavigation.timeStamp;
}
void processInput(int from_floor, int to_floor, int timestamp) {
if ( from_floor != to_floor ){
return;
}
int currentFloor = 0, timeStamp = 0;
currentFloor = queueSystem.getCurrentFloor();
timeStamp = queueSystem.getLatestTimeStamp();
Navigate newUserInput(currentFloor,from_floor,to_floor,timestamp);
queueSystem.liftQueue.insert(newUserInput);
queueSystem.nextInstuctionFloor.insert({from_floor,to_floor});
}
int main() {
return 0;
}