#P1534. 不高兴的津津(升级版)

不高兴的津津(升级版)

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 nn days and determine whether she will be unhappy during these nn days (calculation method: use yesterday’s unhappiness degree plus today’s total class time minus 88 to obtain today’s unhappiness degree); output the sum of the unhappiness degrees after these nn days.

Input Format

The first line contains a single integer nn.

From line 22 to line n+1n+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 nn days.

7
5 3
6 2
7 2
5 3
5 4
0 4
0 6
-2

Hint

Constraints

For all testdata, the school time and the class time each do not exceed 88, and their sum does not exceed 1616, and n3000n \le 3000.

Translated by ChatGPT 5