Step-by-step explanation:
Let 5x, 3x and x be the shares of David, Malachy and Paul.
According to the given condition:
5x = x + 40
[tex] \therefore \: 5x - x = 40 \\ \therefore \: 4x = 40 \\ \therefore \: x = 10 \\ \\ total \: sweets = 5x + 3x + x \\ = 9x \\ = 9 \times 10 \\ = 90[/tex]
Hence, there are total 90 sweets