For this Question: There is a door at Newton School that can be used only by one person at a time i. e either a person can enter from the door or exit but no two people can do it simultaneously. If two people going in the opposite direction arrived at the door at the same time then these 3 cases should be considered:-
1. If the door was not used before or it was not used in the previous second then the person who wants to exit goes first.
2. If the door has been used in the previous second for entering, then the person who wants to enter goes first.
3. If the door has been used in the previous second for exiting, then the person who wants to exist goes first.

If two people arrive at the same time and go in the same direction then the person whose name in the given list comes first will go first.

<b>Note:-</b> To cross the door, it will take exactly one second for each person.The first line of input contains a single integer N containing the number of people The second line of input contains N space-separated integers depicting the arrival time of the ith person. The last line of input containing N space-separated integers which are either 0 or 1. 0 indicates that the person wants to enter and 1 indicates he wants to exit.

<b>Constraints:-</b>
1 &le; N &le; 50000
0 &le; Arrival[i] &le; Arrival [i+1] &le; 10<sup>9</sup>Print N space-separated integers denoting the time at which the ith person will cross the door.Sample Input 1:-
4
0 0 1 5
0 1 1 0

Sample Output 1:-
2 0 1 5


Sample Input 2:-
5
0 1 1 3 3
0 1 0 0 1

Sample Output 2:-
0 2 1 4 3

<b>Explanation:-</b>
At t = 0:- the first and the second person wants to enter and exit. As per the case, 1 2nd person will go first.
At t=1, the first and the 3rd person wants to enter and exit. As per case 3, the 3rd person goes first.
At t= 2, only 1st is the only person standing so he goes.
At t = 3, and 4 no one wants to cross
At t = 5, the 4th person is the only one who wants to cross., I have written this Solution Code: #include <bits/stdc++.h>


using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))

#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)

#define IN(A, B, C) assert( B <= A && A <= C)

#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)

#define FOR1(i,j,a) for(int i=j;i<a;i++)

#define EB emplace_back

#define INF (int)1e9

#define EPS 1e-9

#define PI 3.1415926535897932384626433832795
#define max1 1001
#define MOD 1000000007

#define read(type) readInt<type>()

#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
#define int long long
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}


signed main(){
    fast();

    int n;
    cin>>n;
    int a[n],b[n];
    FOR(i,n){
    cin>>a[i];}
    FOR(i,n){
    cin>>b[i];}

    vector<pair<int,int>> p,q;
    FOR(i,n){
    if(b[i]==0){
        p.EB(make_pair(a[i],i));
    }
    else{
        q.EB(make_pair(a[i],i));
    }
    }
    sort(p.begin(),p.end());
    sort(q.begin(),q.end());
    int j=0,k=0;
int    t=0;
int    x=1;
    int ans[n];
    int pp,qq;
    FOR(i,n){
    ans[i]=-1;}
    while(q.size()!=k || p.size()!=j){
  //          FOR(i,n){
   // out1(ans[i]);}
    //out1(t);

            if(p.size()==j){
                pp=LLONG_MAX;
            }
            else{
    pp=p[j].first;}
    if(q.size()==k){
        qq=LLONG_MAX;
    }
    else{
    qq=q[k].first;}
    if(pp<t){pp=t;}
    if(qq<t){qq=t;}
   // out1(pp);out1(qq);END;
    if(pp==qq){
        if(pp==t){
            if(x==1){
                    ans[q[k].second]=qq;
                k++;
                t=qq+1;

            }
            else{

                    ans[p[j].second]=pp;
                j++;
                t=pp+1;
            }
        }
        else{
            ans[q[k].second]=qq;
            k++;
            t=qq+1;
            x=1;
        }}
        else{
            if(pp<qq){
                x=0;
                ans[p[j].second]=pp;
                t=pp+1;j++;
            }
            else{
                x=1;

                    ans[q[k].second]=qq;
                    t=qq+1;
                    k++;
            }

    }
    }
    FOR(i,n){
    cout<<ans[i]<<" ";}

}
, In this Programming Language: C++, Now tell me if this Code is compilable or not?