【打CF,学算法——二星级】CodeForces 292A SMSC (模拟)
2016-07-13 09:38
411 查看
【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:
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.
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
Output
Input
Output
Input
Output
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了,不知所然。
代码:
提交链接: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:
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.
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; }
相关文章推荐
- LeetCode OJ 42. Trapping Rain Water
- Linux内核实践之工作队列【转】
- DOS 常用命令大全
- 找不到工作就只能培训了
- js实现首页图片的轮播效果
- vs2012误删moc文件解决方法
- Spring.NET学习笔记14——AOP的通知类型(基础篇) Level 300
- Pig搭建环境、安装与应用
- tomcat自动部署方式
- Linux内核实践之序列文件【转】
- underscore源码阅读
- 七夕约课吗?优惠劵大放送
- MyEclipse10.6 myeclipse2013下添加jadClipse反编译插件 .
- Android中View和ViewGroup介绍
- linux初级
- ArcGIS Runtime Sdk for .Net基本介绍
- c语言产生随机数的方法
- 面向对象的程序设计-工厂模式、构造函数模式
- 李洪强iOS开发支付集成之支付宝支付
- poj 2325 Persistent Numbers 贪心+高精度除法