@ankur : I also think u r right....

@everyone : Plz check if my code is right....

p[] : array of petrol
d[]:  array of distance

int FirstPetrolPump(int p[],int d[],int n)
{
int c=0,ThisPetrol=0,FirstPump=0,i;
 for(i=0;i<n && c<n; i++)
{
ThisPetrol+=p[i];
 if(ThisPetrol<d[i])
{
ThisPetrol=0;
FirstPump=i+1;
c=0;
}
else
c++;
}
 while(c<n)
{
ThisPetrol+=p[i%n];
 if(ThisPetrol<d[i%n])
return -1;
 i++;
                c++;
}
return FirstPump;
}

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to