caravans problem - why i get wrong answer ?

hi , i tried to resolve the problem , and this is my code

#include <stdio.h>
#include <stdlib.h>
int main() {
int t;
int n;

while (t--){
      int nb_cars = 0;
      int tmp;
      int low_vit=100000;
      int i;
      for(i=0;i<n;i++) {
              if(tmp<=low_vit) {
                  low_vit = tmp;
return 0;

so what’s the problem , thanks

There is nowhere given in question that the maximum possible speed is 100000. The limit for 32bit integer is not 100000. Now lets say first car to enter circuit is having maximum speed as 100005. So you doesn’t count this car because its bigger than 100000 but you can easily notice that first car to enter will always move at its maximum speed.

Hope this helps !!

1 Like

here the problem set

thank you a lot , that was the problem, i used INT_MAX .