| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 1 초 | 1024 MB | 102 | 21 | 19 | 19.588% |
Farmer John recently installed an electronic gate between his two fields. He can control the gate from his home computer by sending it commands such as "raise 10 inches" and "lower 5 inches".
The gate is considered to be open when it is raised up as high as possible and it is closed when it is lowered to the ground level. FJ had carefully planned the sequence of gate raising and lowering instructions to be sent over the course of the day, but unfortunately a lightning storm scrambled the contents of FJ's computer. His list of N (1 ≤ N ≤ 1000) instructions now appear out of order, for example like the following:
FJ had planned to execute these instructions in chronological order starting at midnight (12:00am) and ending at 11:59pm the same day. He remembers that his instructions would have caused the gate to completely close at least once. Help him determine the total number of minutes the gate would have been closed if he were to execute his instructions in the order he originally planned.
3 1:30pm 1 1:30am -10 1:00am 5
720
At 1:00am the gate is raised 5 inches, then it is lowered 10 inches at 1:30am, and finally it is raised 1 inch at 1:30pm.
Since we know the gate is closed at some point in time, this must have been the interval from 1:30am to 1:30pm, which lasted for 12 hours (720 minutes).