atcoder#ABC305D. [ABC305D] Sleep Log
[ABC305D] Sleep Log
Score : points
Problem Statement
Takahashi keeps a sleep log. The log is represented as an odd-length sequence , where odd-numbered elements represent times he got up, and even-numbered elements represent times he went to bed. More formally, he had the following sleep sessions after starting the sleep log.
- For every integer such that , he fell asleep exactly minutes after starting the sleep log and woke up exactly minutes after starting the sleep log.
- He did not fall asleep or wake up at any other time.
Answer the following questions. For the -th question, you are given a pair of integers such that .
- What is the total number of minutes for which Takahashi was asleep during the minutes from exactly minutes to minutes after starting the sleep log?
Constraints
- is odd.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer in lines. The -th line should contain an integer answering to the -th question.
7
0 240 720 1320 1440 1800 2160
3
480 1920
720 1200
0 2160
480
0
960
Takahashi slept as shown in the following figure.
The answers to each question are as follows.
- Between minutes and minutes after starting the sleep log, Takahashi slept from minutes to minutes, from minutes to minutes, and from minutes to minutes in sleep sessions. The total sleep time is minutes.
- Between minutes and minutes after starting the sleep log, Takahashi did not sleep. The total sleep time is minutes.
- Between minutes and minutes after starting the sleep log, Takahashi slept from minutes to minutes, from minutes to minutes, and from minutes to minutes in sleep sessions. The total sleep time is minutes.
Therefore, the three lines of the output should contain , , and .
21
0 20 62 192 284 310 323 324 352 374 409 452 486 512 523 594 677 814 838 946 1000
10
77 721
255 541
478 970
369 466
343 541
42 165
16 618
222 592
730 983
338 747
296
150
150
49
89
20
279
183
61
177