Let initially, the total number of students = x
Budget for food = Rs. 500
`therefore` Share of each student = Rs. `(500)/(x)`
when 5 students failed to go, then
number of students attended the picnic = x - 5
`therefore` Share of each student now = Rs. `(500)/(x - 5)`
But, in both conditions difference in the share of each student = Rs. 5
`therefore (500)/(x - 5) - (500)/(x) = 5`
`implies 500 [(x - (x -5))/(x(x-5))] = 5`
implies `x^(2) - 5x = 500`
`implies x^(2) - 5x - 500 = 0`
`implies (x - 25) (x + 20) = 0`
`therefore " x = 25 or x = - 20"`
But number of students cannot be negative.
`therefore " "x = 25`
Hence, the number of students who attended the picnic = x - 5 = 25 - 5 = 20
Remark:
If you can solve a problem of two variables with only one variable, then no harm in it.