I want to know what I am missing,
It runs successfully on example test case
Problem Link : SPOJ.com - Problem EXPEDI
#include<bits/stdc++.h>
using namespace std;
bool comparator(vector<int> &A , vector<int> &B){
return A[1]<B[1];
}
int solve( vector<vector<int>> &A ){
// A : { fuel , position }
int currentFuel = 0,stops=0;
priority_queue<int> pq;
for( int i=0; i<A.size()-1; i++ ){
pq.push(A[i][0]);
int requiredFuel = A[i+1][1]-A[i][1];
while( !pq.empty() && (requiredFuel > currentFuel) ){
stops++;
// cout<<pq.top()<<" ";
currentFuel+=pq.top(); pq.pop();
}
if( currentFuel < requiredFuel ) return -1;
currentFuel -= requiredFuel;
}
return stops-1;
}
int main() {
// your code goes here
int t; cin>>t;
while( t-- )
{
int n;
cin>>n;
vector<vector<int>> A;
A.push_back( {0,0} );
for(int i=0; i<n; i++){
int a,b; cin>>a>>b;
A.push_back({b,a});
// {fuel , distance from destination}
}
cin>>A[0][1]>>A[0][0];
int start=A[0][1];
A.push_back({0,0});
for(auto &temp:A){
// {fuel , distance from start}
temp[1]=start-temp[1];
}
sort(A.begin(), A.end(),comparator);
cout<<solve( A );
}
return 0;
}