codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

292A.md (3194B)


      1 Source: https://codeforces.com/problemset/problem/292/A
      2 
      3 A. SMSC
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 Some large corporation where Polycarpus works has its own short message service center (SMSC). The center's task is to send all sorts of crucial information. Polycarpus decided to check the efficiency of the SMSC.
     22 
     23 For that, he asked to give him the statistics of the performance of the SMSC for some period of time. In the end, Polycarpus got a list of *n* tasks that went to the SMSC of the corporation. Each task was described by the time it was received by the SMSC and the number of text messages to send. More formally, the *i*-th task was described by two integers *t**i* and *c**i* — the receiving time (the second) and the number of the text messages, correspondingly.
     24 
     25 Polycarpus knows that the SMSC cannot send more than one text message per second. The SMSC uses a queue to organize its work. Consider a time moment *x*, the SMSC work at that moment as follows:
     26 
     27 1. If at the time moment *x* the queue is not empty, then SMSC sends one message from the queue (SMSC gets the message from the head of the queue). Otherwise it doesn't send messages at the time moment *x*.
     28 2. If at the time moment *x* SMSC receives a task, then it adds to the queue all the messages from this task (SMSC adds messages to the tail of the queue). Note, that the messages from the task cannot be send at time moment *x*. That's because the decision about sending message or not is made at point 1 before adding these messages to the queue.
     29 
     30 Given the information about all *n* tasks, Polycarpus wants to count two values: the time when the last text message was sent and the maximum size of the queue at some time. Help him count these two characteristics he needs to evaluate the efficiency of the SMSC.
     31 
     32 Input
     33 
     34 The first line contains a single integer *n* (1 ≤ *n* ≤ 103) — the number of tasks of the SMSC. Next *n* lines contain the tasks' descriptions: the *i*-th line contains two space-separated integers *t**i* and *c**i* (1 ≤ *t**i*, *c**i* ≤ 106) — the time (the second) when the *i*-th task was received and the number of messages to send, correspondingly.
     35 
     36 It is guaranteed that all tasks were received at different moments of time. It is guaranteed that the tasks are sorted in the chronological order, that is, *t**i* < *t**i* + 1 for all integer *i* (1 ≤ *i* < *n*).
     37 
     38 Output
     39 
     40 In a single line print two space-separated integers — the time when the last text message was sent and the maximum queue size at a certain moment of time.
     41 
     42 Examples
     43 
     44 Input
     45 
     46 ```
     47 2  
     48 1 1  
     49 2 1
     50 ```
     51 
     52 Output
     53 
     54 ```
     55 3 1
     56 ```
     57 
     58 Input
     59 
     60 ```
     61 1  
     62 1000000 10
     63 ```
     64 
     65 Output
     66 
     67 ```
     68 1000010 10
     69 ```
     70 
     71 Input
     72 
     73 ```
     74 3  
     75 3 3  
     76 4 3  
     77 5 3
     78 ```
     79 
     80 Output
     81 
     82 ```
     83 12 7
     84 ```
     85 
     86 Note
     87 
     88 In the first test sample:
     89 
     90 * second 1: the first message has appeared in the queue, the queue's size is 1;
     91 * second 2: the first message is sent, the second message has been received, the queue's size is 1;
     92 * second 3: the second message is sent, the queue's size is 0,
     93 
     94 Thus, the maximum size of the queue is 1, the last message was sent at the second 3.