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

View as PDF

Submit solution

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

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 N paper and spews it out the front once every second.

He plans to perform A actions during the printer's operation: for the i^{th} action, Y_i paper will be either added to or removed from the feed at X_i seconds since powering on the printer.

Keep in mind that the feed has a maximum capacity M 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 N and M (0 \leq N \leq M \leq 1000), the initial paper amount and the maximum printer feed capacity, respectively.

The next line contains an integer A (0 \leq A \leq 10), the number of actions to follow.

The next A lines contain two spaced integers X_i and Y_i (0 \leq X_i \leq 2000, -500 \leq Y_i \leq 500), describing that Y_i paper was either added to or removed from the feed at X_i seconds. Actions are listed in chronological order, and only one action can occur in a second. A negative Y_i 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.

Output Specification

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

Sample Input 1

4 10
2 6
5 -2
8 11

Sample Output 1

The printer jams at 8 second(s).

Sample Input 2

4 10
2 6
5 -3
8 11

Sample Output 2

The printer melts at 8 second(s).


  • 1
    Marky  commented on Dec. 16, 2018, 6:23 p.m.


  • 1
    kylechang  commented on Feb. 20, 2017, 8:39 p.m.

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

    • 1
      leonchen0613  commented on Feb. 20, 2017, 8:55 p.m.

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

  • 2
    Epicnerdking  commented on Feb. 20, 2017, 12:58 p.m.

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

    • 2
      d  commented on Feb. 20, 2017, 1:37 p.m.

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