This is a problem from a mathematical contest I was unable to answer. I am placing this problem with both the recreational math and calculus tags because I think derivatives are needed. The problem is:
A train stops in all $n$ stations along its route (including the initial and last ones). At each station, a number of passengers equal to the number of stations ahead get on the train, each one going to different stations. If the maximum number of passengers on the train is $420$ , find the number $n$ .
Any idea? I found $n=40$ , approximately, but it was wrong.
At each station, the number of passengers that get off is equal to the number of stations behind that station, and the number of passengers that get on is equal to the number of stations in front of the train. Therefore, clearly, it must be in the middle of the ride that the number of passengers aboard the train is at its largest.
If there are an odd number of stations (including both the end stations), then the maximal number of passengers happens at the stretch to and the stretch from the middle station. If there are an even number of stations, then the maximal number of passengers happens at the stretch between the two middle stations.
So, if there are $N$ stations, and we are at station number $n$ (including the starting station), there are $N-n$ passengers getting on, and $n-1$ passengers getting off. So the total number of passengers on the train as it leaves that station is $$ \sum_{i = 1}^n\Big((N-i) - (i-1)\Big) = \sum_{i = 1}^n\Big(N - 2i + 1\Big)\\ = nN - n(n+1) + n\\ = Nn-n^2 = n(N-n) $$ This has a maximum at $n = N/2$. However, if $N$ is odd, then this is nonsensical in the context of the actual train ride, and we're instead looking for the value at $n = \frac{N-1}2$, or equivalently $n = \frac{N+1}2$. (Station number $\frac{N+1}2$ is the middle station where an equal number of passengers get on as get off, so the number of passengers doesn't change from the station before.)
So, assuming the maximal number of passengers is $420$, what is $N$? Let's first assume that $N$ is even, and see what we get: $$ 420 = N\cdot \frac N2 - \left(\frac N2\right)^2\\ 420 = \frac14N^2\\ \sqrt{1680} = N $$ which doesn't make sense. So let's see what happens if $N$ is odd: $$ 420 = N\cdot \frac{N-1}2 - \left(\frac{N-1}2\right)^2\\ 420 = \frac14N^2-\frac14\\ \sqrt{1681} = N $$ which works out to $N = 41$, which is indeed odd, and everything is fine.