I managed to do a better formula than the one above (it's an array formula too):
=SUMPRODUCT(C12:E12,IF($C$15:$E$15="",0,N(OFFSET($C$6,MATCH($C$15:$E$15,$B$ 6:$B$7,0)-1,0))))

As for the problem of the merged cells array formula, I noticed that merged cells can have an array formula by doing this:

1 - Unmerge the cells where you want to put the formula;
2 - Put the array formula on the single top cell;
3 - Merge again as desired;
4 - Copy the formula to the others cells.