Description
A social network for dogs called DH (DogHouse) has
We know that each server takes one second to recompress a one minute fragment. Thus, any server takes
We know the time when each of the
For each video find the moment it stops being recompressed.
Input
The first line of the input contains integers
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;
}