question CHEFRES

Can someone please point out the mistake I’m committing here. I’m getting a partially correct solution for the question Contest Page | CodeChef. Here goes my code.
CODE

#include<bits/stdc++.h>

using namespace std;

struct interval{

    int startTime, endTime;

   //Default constructor

    interval(){

        startTime = 0;

        endTime=0;

    }

   //Parameterised constructor

    interval(int start, int end){

        startTime = start;

        endTime = end;

    }

};

void getInterval(vector& newTimeIntervals, int intervalNumber){

int start, end;

for(int i=0;i<intervalNumber;i++){

    cin>>start>>end;

    interval value ( start, end );

    newTimeIntervals.push_back(value);

}

cout<<endl;

}

bool comp (const interval& a,const interval& b){

return a.startTime < b.startTime;

}

int result(vector& newIntervals, int arrivalTime){

int  ans;

interval value;

value.startTime=arrivalTime;

auto ogIndex= lower_bound( newIntervals.begin(),newIntervals.end(), value, comp);

auto tempIndex= ogIndex;

auto prevIndex= --ogIndex;

//edge case first

if(tempIndex == newIntervals.end())

    ans = -1;

else if(tempIndex == newIntervals.begin())

    ans = tempIndex->startTime - arrivalTime;

else{

    if(  arrivalTime < prevIndex->endTime )

        ans = 0;

    else if( arrivalTime <= tempIndex->startTime && arrivalTime >= prevIndex->endTime)

         ans = tempIndex->startTime - arrivalTime;    

}

return ans;    

}

int main(){

int t;

cin>>t;

while(t--){

    int intervalNumber, people;

    cin>>intervalNumber>>people;

    vector<interval> timeIntervals;

    getInterval(timeIntervals, intervalNumber);

    sort(timeIntervals.begin(), timeIntervals.end(), comp);

    while(people--){

        int currentInterval;

        cin>>currentInterval;

        cout<<result(timeIntervals, currentInterval)<<endl;

    }

    cout<<endl;    

}

return 0;    

}