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

View as PDF

Submit solution


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 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^\text{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 \le N \le M \le 1\,000), the initial paper amount and the maximum printer feed capacity, respectively.

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

The next A lines contain two spaced integers X_i and Y_i (0 \le X_i \le 2\,000, -500 \le Y_i \le 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. Note that during each second, starting from 0, 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).

Comments


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

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


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

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


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

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


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

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