【CF简介】

提交链接:CF 292A

题面:

A. SMSC
time limit per test   2 seconds
memory limit per test  256 megabytes
input standard input
output standard output

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 ti and ci — 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.

Input

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 ti and ci (1 ≤ ti, ci ≤ 106) — 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, ti < ti + 1 for all integer i (1 ≤ i < n).

Output

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.

Examples
Input
2
1 1
2 1

Output
3 1

Input
1
1000000 10

Output
1000010 10

Input
3
3 3
4 3
5 3

Output
12 7

Note

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.

题意:

给定n个任务,每项任务都有任务到达时间,执行时间。每次接受到任务,就加入到任务队列中,刚收到的包是不能发送的,现有包是可以发送的。问完成全部发送的最后时间是什么,以及在整个过程任务队列(消息包)的最大长度。

解题:

开始看错了,以为刚收到新任务那一刻是不能发送消息的,实际上是可以的,只要原来有包要发,但刚到的包是不能发的(如果我没理解错的话),那么题目的样例二就应该是1000011才对.....,按照刚收到包就可以发写的,然后A了,不知所然。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
int t[1005],c[1005];
int main()
{int n,cur,sz,ans_sz,p,endTime;scanf("%d",&n);for(int i=0;i<n;i++)scanf("%d%d",&t[i],&c[i]);p=0;ans_sz=0;while(p<n){cur=t[p];sz=c[p];endTime=t[p]+c[p];if(sz>ans_sz)ans_sz=sz;p++;while(p<n&&t[p]<endTime){cur=t[p];endTime+=c[p];sz=endTime-cur;if(sz>ans_sz)ans_sz=sz;p++;}      }printf("%d %d\n",endTime,ans_sz);return 0;
}

【打CF,学算法——二星级】CodeForces 292A SMSC (模拟)相关推荐

  1. 【打CF,学算法——二星级】Codeforces Round #313 (Div. 2) B. Gerald is into Art(水题)...

    [CF简单介绍] 提交链接:http://codeforces.com/contest/560/problem/B 题面: B. Gerald is into Art time limit per t ...

  2. 【打CF,学算法】CodeForces网站简介

    转自豆瓣:https://www.douban.com/review/5800694/ 你应当知道的关于Codeforces的事情 关于codeforces的文字 Codeforces 简称: cf( ...

  3. 《趣学算法(第2版)》读书笔记 Part 1 :如何高效学习算法

    14天阅读挑战赛 系列笔记链接 <趣学算法(第2版)>读书笔记 Part 1 :如何高效学习算法 <趣学算法(第2版)>读书笔记 Part 2 :算法入门 <趣学算法(第 ...

  4. 当前进度,已学算法,未做题目

    当前学习 CSP-S备战中 已学算法 从初一开始算起,按照时间顺序排序 算法简称 算法全称 备注 无 高精度 比较基础的算法 d e p t h f i r s t s e a r c h ( D F ...

  5. 零起点学算法104——第几天?

    零起点学算法104--第几天? Time Limit: 1 Sec  Memory Limit: 128 MB   64bit IO Format: %lld Description 给定一个日期,输 ...

  6. 零起点学算法24——求正弦和余弦

    零起点学算法24--求正弦和余弦 Time Limit: 1 Sec  Memory Limit: 64 MB   64bit IO Format: %lld Description 输入一个正整数n ...

  7. 零起点学算法22——华氏摄氏温度转换

    零起点学算法22--华氏摄氏温度转换 Time Limit: 1 Sec  Memory Limit: 64 MB   64bit IO Format: %lld Description 输入一个华氏 ...

  8. 零起点学算法17——比较2个数大小

    零起点学算法17--比较2个数大小 Time Limit: 1 Sec  Memory Limit: 64 MB   64bit IO Format: %lld Description 输入2个整数, ...

  9. 零起点学算法11——求梯形面积

    零起点学算法11--求梯形面积 Time Limit: 1 Sec  Memory Limit: 64 MB   64bit IO Format: %lld Description 水题 Input ...

最新文章

  1. Nginx配置文件粗解
  2. linux编译安装的好处,Linux学习—源码安装
  3. Spring WebSocket初探2 (Spring WebSocket入门教程)
  4. boot lib分离 spring_SpringBoot打包分离依赖jar和资源文件
  5. 服务器根没有web文件系统,Web服务器
  6. socket和URLConnection
  7. numpy教程:numpy基本数据类型及多维数组元素存取
  8. Matlab简单教程:矩阵
  9. ubuntu9.10之grub.cfg详解
  10. 云服务器上安装jboss_jboss下载_精通jboss下载_下载与安装jboss-华军软件园
  11. jsp在线编辑器|PHP在线编辑器|asp在线编辑器|.net在线编辑器|asp.net在线编辑器|在线Word编辑器
  12. echarts世界地图(含中国省份地图),中国省份下钻到县,点击按钮返回上一级
  13. windows中查看端口占用情况以及删除端口
  14. c语言的typedef struct 对应java参数类型,JNA实战系列:02JNA与C语言中的数据类型映射以及复杂结构体传参示例...
  15. java英文面试常见问题归纳
  16. 微博微信QQ等开发者平台注册应用时提交签名信息的坑点。
  17. 神仙科研夫妇!浙大博士夫妻赴耶鲁深造,如今归国任教985
  18. [UE4]射击产生弹孔:Spawn Decal At Location、Spawn Decal Attached
  19. Windows10下VMWare Workstation 16 Pro 安装CentOS 7
  20. 查找网站真实IP的方法大全

热门文章

  1. 6个动作轻松消灭肥屁股大肚子
  2. MySQL初级练习题
  3. 地砖LED显示屏是什么?互动感应LED地砖屏原理特点解析
  4. 从电池中管理使用电动车(EVS)和电力注射构成控制EV的充电和排放作为有吸引力的研究领域的问题
  5. 用Halo搭建个人博客-前置工作
  6. 【FLASH存储器系列七】NAND FLASH之ONFI规范
  7. matlab polyfit计算过程,matlab中的polyfit函数。
  8. LaTeX 系列(1) —— 介绍、安装和使用
  9. 一道算法题:圆桌会议
  10. 乐山市计算机学校成教中心,乐山市计算机学校:网络教育开学典礼顺利举行