Statistics of Recompre…
来源:互联网 发布:js或 编辑:程序博客网 时间:2024/06/04 19:01
Description
A social network for dogs called DH (DogHouse)has
We know that each server takes one second to recompress a oneminute fragment. Thus, any servertakes
We know the time when each ofthe
For each video find the moment it stops being recompressed.
Input
The first line of the input containsintegers
Next
Output
Print
Sample Input
3 2
1 5
2 5
3 5
6
7
11
6 1
1 1000000000
2 1000000000
3 1000000000
4 1000000000
5 1000000000
6 3
1000000001
2000000001
3000000001
4000000001
5000000001
5000000004
题目意思就是有一堆机器和一些工程,每个工程都有出现时间和完成它所需要的时间,求出每个工程最快完成的时间。题目中有一个明显的单词queue,因此用优先队列来进行维护。并且输入已经将序列排好,不解的是我的ide居然不能完成greater的函数。刚学习了队列,用的不是很熟,占了不少内存。中间也有不少废代码,可以消去。
#include
#include
#include
using namespace std;
struct Video{
long long st;
long long ed;
long long id;
bool operator <(const Video&a)const
{
return st + ed>a.ed + a.st;
}
}video[500005];
long long re[500005];
priority_queueq;
int main()
{
ios::sync_with_stdio(false);
long long n, k, i, j, ans;
cin >> n >> k;
for (i = 1; i <= n; i++)
{
cin >> video[i].st >> video[i].ed;
video[i].id = i;
}
re[1] = video[1].ed + video[1].st;
q.push(video[1]);
ans = 1;
for (i = 2; i <= n; i++)
{
if (!q.empty())
{
if (q.top().ed + q.top().st <= video[i].st)
{
re[i] = video[i].st + video[i].ed;
q.pop();
}
else
{
if (ans < k)
{
ans++;
re[i] = video[i].st + video[i].ed;
}
else
{
video[i].st = q.top().st + q.top().ed;
re[i] = video[i].st + video[i].ed;
q.pop();
}
}
q.push(video[i]);
}
else
{
re[i] = video[i].st + video[i].ed;
q.push(video[i]);
ans++;
}
}
for (i = 1; i <= n; i++)
cout << re[i] << "\n";
return 0;
}
- Statistics of Recompre…
- Statistics Package (ST…
- Statistics Package (ST…
- resource is out of sync with t…
- identifier of an …
- failure of the “Grid Installatio…
- Solution of Enable extension for…
- Filtering of Hierarchical Data i…
- Journal of Machine Learning Rese…
- To add a multiplexed copy of the…
- ZOJ 1504(POJ 1244) Slots of Fun…
- hdu 1692 Destroy the Well of Lif…
- Lesson 47 A cup of coffee 一杯咖…
- Picture of my baby when 2 monthe…
- To represent Asia - the issue of…
- I am the captain of my sou…
- poj 3083 Children of the Candy C…
- object is not an instance of dec…
- Robbers
- Protecting the Flowers
- ACdream的高速公路
- 二进制暴力
- Packets
- Statistics of Recompre…
- leetcode Length of Last Word
- Stall Reservations
- Milking Time
- 全面SSH 远程操作与端口转发,远程copy
- JAVA序列化机制的深入研究
- css中的relative(相对位置)和absolute(绝对位置)
- Android Studio使用注意事项
- hiho一下 第四十九周