Suppose $x$ be a number of the students who have decided that they will go for a picnic.
Let each student will contribute to $y$ Rs to the total sum of $500$ Rs.
So we can write this way; $x * y =500$ $---------(1)$
Now then $5$ students have decided that they will not go for a picnic.
So, $(x-5)*(y+5)= 500$
$xy + 5x -5y -25 = 500$
$500 + 5x -5y -25 = 500$
$x - y = 5$ $------------(2)$
On solving $1$ and $2$ ;
we get $x =25$ but $5$ students did not got for picnic, So only $20$ students go for picnic..