Take 1 from the first bag, 2 from the second bag, and so on, and then take 10 from the tenth bag.
If both are 50g, the total weight should be 50x (1+2+3+). . +10) = 2750g
Now weigh it, then subtract the total weight from 2750 and divide it by 50-45=5, and the number is 45 grams!
Do it!