Try this...

Data Range
A
B
C
D
1
Name
Apples
Total
2
Ken
2
10
3
James
5
4
James
5
5
John
3
6
------
------
------
------


This array formula** entered in D2:

=SUM(IF(FREQUENCY(MATCH(A2:A5&B2:B5,A2:A5&B2:B5,0),ROW(B2:B5)-ROW(B2)+1),B2:B5))

** array formulas need to be entered using the key
combination of CTRL,SHIFT,ENTER (not just ENTER).
Hold down both the CTRL key and the SHIFT key
then hit ENTER.