Weightlifter
Time limit1sMemory limit1024 MB
Sum the evening-minus-morning body mass increases on training days to get the total muscle gain.
- Level
Easy2 of 10
- Topics
- Implementation, Array
- Solved
- No attempts yet
Problem
A weightlifter is preparing for a competition and wants to analyze the muscle mass he has gained. He reviews his training records for the last days. For each day, his body mass in the morning and in the evening are known. It is also known on which days he trained.
On training days, an increase in body mass, if it happened, counts as a gain in muscle mass. If his body mass decreased or he did not train, the muscle gain for that day is .
Help the weightlifter find his total gain in muscle mass.
Input
The first line contains , the number of days to analyze ().
The second line contains integers. The -th integer is if there was training on day , and if there was no training on day .
The next lines contain the body mass measurements. Each line has two integers and , the body mass in grams ().
Output
Print one integer, the total gain in muscle mass.