D. Statistics of Recompressing Videos
time limit per test 3 seconds
memory limit per test 256 megabytes
input standard input
output standard output

A social network for dogs called DH (DogHouse) has k special servers to recompress uploaded videos of cute cats. After each video is uploaded, it should be recompressed on one (any) of the servers, and only after that it can be saved in the social network.

We know that each server takes one second to recompress a one minute fragment. Thus, any server takes m seconds to recompress am minute video.

We know the time when each of the n videos were uploaded to the network (in seconds starting from the moment all servers started working). All videos appear at different moments of time and they are recompressed in the order they appear. If some video appeared at time s, then its recompressing can start at that very moment, immediately. Some videos can await recompressing when all the servers are busy. In this case, as soon as a server is available, it immediately starts recompressing another video. The videos that await recompressing go in a queue. If by the moment the videos started being recompressed some servers are available, then any of them starts recompressing the video.

For each video find the moment it stops being recompressed.

Input

The first line of the input contains integers n and k (1 ≤ n, k ≤ 5·105) — the number of videos and servers, respectively.

Next n lines contain the descriptions of the videos as pairs of integers si, mi (1 ≤ si, mi ≤ 109), where si is the time in seconds when the i-th video appeared and mi is its duration in minutes. It is guaranteed that all the si's are distinct and the videos are given in the chronological order of upload, that is in the order of increasing si.

Output

Print n numbers e1, e2, ..., en, where ei is the time in seconds after the servers start working, when the i-th video will be recompressed.

Examples
input
3 2
1 5
2 5
3 5
output
6
7
11
input
6 1
1 1000000000
2 1000000000
3 1000000000
4 1000000000
5 1000000000
6 3
output
1000000001
2000000001
3000000001
4000000001
5000000001
5000000004
#include<stdio.h>
#include<string.h>
#include<queue>
using namespace std;
#define lol long long
struct node
{
lol pos;lol end;
friend bool operator < (node a,node b)
{
return a.end>b.end;
}
}now,nex;
lol ans[];
int main()
{
freopen("water.in","r",stdin);
freopen("water.out","w",stdout);
lol n,m;
while(~scanf("%lld%lld",&n,&m))
{
priority_queue<node>s;
for(lol i=;i<n;i++)
{
lol a,b;
scanf("%lld%lld",&a,&b);
while(s.size()>&&s.top().end<a)ans[s.top().pos]=s.top().end,s.pop();
if(s.size()<m)
{
now.end=a+b;
now.pos=i;
s.push(now);
}
else
{
now.end=s.top().end+b;
ans[s.top().pos]=s.top().end;
s.pop();
now.pos=i;
s.push(now);
}
}
while(!s.empty())
{
ans[s.top().pos]=s.top().end;
s.pop();
}
for(lol i=;i<n;i++)
{
printf("%lld\n",ans[i]);
}
}
}

D. Statistics of Recompressing Videos的更多相关文章

  1. codeforces 523D tatistics of Recompressing Videos

    一个称为DH(DogHouse)的狗的社交网络有k台专用服务器来重新上传可爱的猫的上传视频.每个视频上传后,应该在一个(任何)服务器上重新压缩,之后才可以保存在社交网络中. 我们知道每个服务器需要一秒 ...

  2. Photodesk for Mac(Instagram 桌面客户端)破解版安装

    1.软件简介    PhotoDesk - for Instagram 是 macOS 系统上一款 Instagram 客户端,可以让大家在 Mac 上观看朋友的新照片.或是最近热门的作品,也可以 f ...

  3. ABBA BABA statistics

    The ABBA BABA statistics are used to detect and quantify an excess of shared derived alleles, which ...

  4. SQL Server 的 Statistics 簡介

    當你要清空「資料表(table)」,或倒入大量「資料(data;record)」,或公司「資料庫(database)」改用新版本要資料大搬家…等情形,不只是要重建「索引(index)」,還應要重建或更 ...

  5. SP2-0618: 无法找到会话标识符。启用检查 PLUSTRACE 角色 SP2-0611: 启用 STATISTICS 报告时出错

    援引: SP2-0618: 无法找到会话标识符.启用检查 PLUSTRACE 角色 SP2-0611: 启用 STATISTICS 报告时出错 问题描述及解决方法: SQL*Plus: Release ...

  6. Spark MLlib 之 Basic Statistics

    Spark MLlib提供了一些基本的统计学的算法,下面主要说明一下: 1.Summary statistics 对于RDD[Vector]类型,Spark MLlib提供了colStats的统计方法 ...

  7. SQL优化 CREATE STATISTICS

    CREATE STATISTICS 语法: https://msdn.microsoft.com/zh-cn/library/ms188038.aspx STATISTICS优化中的使用案例: htt ...

  8. [转] 利用SET STATISTICS IO和SET STATISTICS TIME 优化SQL Server查询性能

    首先需要说明的是这篇文章的内容并不是如何调节SQL Server查询性能的(有关这方面的内容能写一本书),而是如何在SQL Server查询性能的调节中利用SET STATISTICS IO和SET ...

  9. 性能调优:理解Set Statistics IO输出

    性能调优是DBA的重要工作之一.很多人会带着各种性能上的问题来问我们.我们需要通过SQL Server知识来处理这些问题.经常被问到的一个问题是:早上这个存储过程运行时间还是可以的,但到了晚上就很慢很 ...

随机推荐

  1. Linux 中安装软件报缺少共享库文件的错误

    linux 安装一些如软件 或者相关的模块时,经常报出缺少一些依赖包的 libxxx.so等的共享库文件 首先找到 该共享库文件 然后查看/etc/ld.so.conf 这个文件记录了编译时使用的动态 ...

  2. python之django入门

    一.搭建开发环境 使用virualenv创建虚拟python环境 pip install virtualenv [root@master djiango]# find / -name virtuale ...

  3. 「NOIP2016」「P1850」 换教室(期望dp

    题目描述 对于刚上大学的牛牛来说,他面临的第一个问题是如何根据实际情况申请合适的课程. 在可以选择的课程中,有 2n2n 节课程安排在 nn 个时间段上.在第 ii(1 \leq i \leq n1≤ ...

  4. bzoj 4319: Suffix reconstruction 后缀数组+构造

    题目大意 给定后缀数组sa,要求构造出满足sa数组的字符串.或输出无解\(n\leq 5*10^5\) 题解 我们按照字典序来考虑每个后缀 对于\(Suffix(sa[i])\)和\(Suffix(s ...

  5. 【LeetCode】091. Decode Ways

    题目: A message containing letters from A-Z is being encoded to numbers using the following mapping: ' ...

  6. 用linqpad来插入多条数据

    其中Customers为数据库的某个表名, Custom自动被默认为单条记录的对象, 利用构造,InsertOnSubmit, 以及SubmitChanges实现插入数据. 注意:linqpad的la ...

  7. Vijos:P1234口袋的天空

    背景 小杉坐在教室里,透过口袋一样的窗户看口袋一样的天空. 有很多云飘在那里,看起来很漂亮,小杉想摘下那样美的几朵云,做成棉花糖. 描述 给你云朵的个数N,再给你M个关系,表示哪些云朵可以连在一起. ...

  8. Selenium实战脚本集—新浪微博发送QQ每日焦点

    Selenium实战脚本集-新浪微博发送QQ每日焦点 http://www.spasvo.com/ceshi/open/kygncsgj/Selenium/201549150822.html 背景 很 ...

  9. ZOJ 2671 Cryptography 矩阵乘法+线段树

    B - Cryptography Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Subm ...

  10. 3-C++程序的结构1.5

    多文件结构和编译预处理命令 1.c++程序的一般组织结构 通常一个项目至少划分为三个文件:类定义文件(*.h文件).类实现文件(*.cpp文件)和类的使用文件(*.cpp,主函数文件).如下: 这三个 ...