1- Allah looks at the quality of the deed. Sometimes a few years of good quality deeds are higher in value in the many years of lesser quality.
2- Allah takes our intentions into consideration when rewarding us. If the believer who died earlier had the intention to always obey Allah for as long as he lives, Allah will grant him that reward.
3- The one who died earlier might have less sins than the one who lives longer, so the greater number of sins committed by the longer living person can offset some of the more deeds he offered.