I tried spoj http://www.spoj.com/problems/EXPEDI problem my code run perfectly for all test cases in spoj toolkit but when i submitting it throws me a segmentation fault
include
define ll long long indent preformatted text by 4 spaces
using namespace std;
struct cmpp
{
bool operator()(pair<ll,pair > a, pair<ll, pair > b)
{
return a.first>b.first;
}
};
bool como(pair a,pair b)
{
return a.first<b.first;
}
int main()
{
ll t;
scanf("%lld",&t);
while(t--)
{
ll n;
scanf("%lld",&n);
vector< pair > a(n);
for(ll i=0;i<n;i++)
scanf("%lld%lld",&a[i].first,&a[i].second);
ll distance,intialpetrol;
scanf("%lld%lld",&distance,&intialpetrol);
for(ll i=0;i<n;i++)
a[i].first=distance-a[i].first;
sort(a.begin(),a.end(),como);
priority_queue< pair<ll, pair >,vector< pair< ll ,pair > > , cmpp > pq;
pq.push(pair<ll, pair >(0,pair(intialpetrol,0)));
ll res=-1;
if(distance)
while(!pq.empty())
{
ll stop=pq.top().first;
ll dist=pq.top().second.first;
ll i=pq.top().second.second;
pq.pop();
if((distance-dist)<=0)
{
res=stop;
break;
}
for(;i<n;i++)
{
if(a[i].first>dist)
break;
ll temp=dist+a[i].second;
pq.push(pair< ll ,pair >(stop+1,pair(temp,i+1)));
}
}
printf("%lld\n",res);
}
return 0;
}