## TLE '16 Contest 6 (Mock CCC) J1 - Paper Printing

View as PDF

Points: 3 (partial)
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type

Leon has recently purchased a defective printer that won't stop printing! Once powered on, the printer immediately draws from the initial feed of paper and spews it out the front once every second.

He plans to perform actions during the printer's operation: for the action, paper will be either added to or removed from the feed at seconds since powering on the printer.

Keep in mind that the feed has a maximum capacity of paper that it can hold - additional paper forced into the feed would cause a paper jam!

However, if at any given second the printer's feed is empty, it will attempt (but fail) to continuously draw paper. As a result, the printer will rapidly overheat, causing it to quickly melt after a full second (unfortunately short-circuiting, like CCC Junior, doesn't pay).

What will become of Leon's printer?

#### Input Specification

The first line contains two spaced integers and , the initial paper amount and the maximum printer feed capacity, respectively.

The next line contains an integer , the number of actions to follow.

The next lines contain two spaced integers and , describing that paper was either added to or removed from the feed at seconds. Actions are listed in chronological order, and only one action can occur in a second. A negative value means that paper is to be taken away from the feed. You may assume that Leon will never remove more paper from the feed than there currently is. Note that during each second, starting from , Leon performs his action, if any, first, before the printer tries to draw from the feed.

#### Output Specification

When and how Leon's printer breaks. Follow the output formats shown below.

#### Sample Input 1

4 10
3
2 6
5 -2
8 11

#### Sample Output 1

The printer jams at 8 second(s).

#### Sample Input 2

4 10
3
2 6
5 -3
8 11

#### Sample Output 2

The printer melts at 8 second(s).

• commented on Feb. 21, 2017, 1:39 a.m.

Does the printer print if paper is removed/added into the feed?

• commented on Feb. 21, 2017, 1:55 a.m.

Yes, the printer prints while paper is removed/added to the feed.

• commented on Feb. 20, 2017, 5:58 p.m.

How much paper is "spewed" out the front every second?

• commented on Feb. 20, 2017, 6:37 p.m.

One piece of paper is spewed out at the end of every second.