I think the other responder was confused (as I was) because your target total did not include Mssrs. A, B, and C. So your total on line 35 doesn't include lines 17-19.
My solution (attached) cheats a bit insofar as I created a table off to the side that calculates the breakdown of each employee's cost by department. This information can be used in any number of ways.
You can do the cost allocation for individual employees via formulas, as I've done for Mssrs. A, B, and C in the attachment. But it's not a feasible solution to use this approach if you have 1000+ employees as you indicated.
Hope this helps.
bb