A8879 | SMSC
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
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:
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$ .
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.
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.
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.
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:
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$ .
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.
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.
输入格式
The first line contains a single integer $n$ $(1<=n<=10^{3})$ — 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}<=10^{6})$ — the time (the second) when the $i$ -th task was received and the number of messages to send, correspondingly.
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)$ .
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)$ .
输出格式
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.
输入输出样例
输入 #1
2 1 1 2 1
输出 #1
3 1
输入 #2
1 1000000 10
输出 #2
1000010 10
输入 #3
3 3 3 4 3 5 3
输出 #3
12 7
In the first test sample:
- second 1: the first message has appeared in the queue, the queue's size is 1;
- second 2: the first message is sent, the second message has been received, the queue's size is 1;
- second 3: the second message is sent, the queue's size is 0,
Thus, the maximum size of the queue is 1, the last message was sent at the second 3.
- second 1: the first message has appeared in the queue, the queue's size is 1;
- second 2: the first message is sent, the second message has been received, the queue's size is 1;
- second 3: the second message is sent, the queue's size is 0,
Thus, the maximum size of the queue is 1, the last message was sent at the second 3.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted