P1534 Unhappy Jinjin (Upgraded Version)
Description
Jinjin has entered middle school. Her mom thinks she should study harder, so besides attending school, Jinjin also has to go to the review classes her mom enrolled her in. In addition, every day her mom takes her to learn recitation, dance, and piano. However, if Jinjin studies for more than eight hours in a day, she becomes unhappy, and the longer she studies, the more unhappy she becomes.
Different from the first problem of NOIp2004 Junior: assume Jinjin will not be unhappy because of other things, but her unhappiness (and of course her happiness) will carry over to the next day. Please check Jinjin’s schedule for the next $n$ days and determine whether she will be unhappy during these $n$ days (calculation method: use yesterday’s unhappiness degree plus today’s total class time minus $8$ to obtain today’s unhappiness degree); output the sum of the unhappiness degrees after these $n$ days.
Input Format
The first line contains a single integer $n$.
From line $2$ to line $n+1$, each line contains two integers, representing the school time and the extracurricular tutoring time for that day.
Output Format
A single integer: the sum of the unhappiness degrees after these $n$ days.
Explanation/Hint
Constraints
For all testdata, the school time and the class time each do not exceed $8$, and their sum does not exceed $16$, and $n \le 3000$.
Translated by ChatGPT 5