【NWERC2015】【BZOJ4425】AssigningWorkstations分配工作站

Description

Penelope is part of the admin team of the newly built supercomputer. Her job is to assign workstations to the researchers who come here to run their computations at the supercomputer.
Penelope is very lazy and hates unlocking machines for the arriving researchers. She can unlock the machines remotely from her desk, but does not feel that this menial task matches her qualifications. Should she decide to ignore the security guidelines she could simply ask the researchers not to lock their workstations when they leave, and then assign new researchers to workstations that are not used any more but that are still unlocked. That way, she only needs to unlock each workstation for the first researcher using it, which would be a huge improvement for Penelope.
Unfortunately, unused workstations lock themselves automatically if they are unused for more than mm minutes. After a workstation has locked itself, Penelope has to unlock it again for the next researcher using it. Given the exact schedule of arriving and leaving researchers, can you tell Penelope how many unlockings she may save by asking the researchers not to lock their workstations when they leave and assigning arriving researchers to workstations in an optimal way? You may assume that there are always enough workstations available.
Input
The input consists of:
one line with two integers n (1≤n≤300000), the number of researchers, and m (1≤m≤10^8), the number of minutes of inactivity after which a workstation locks itself;
n lines each with two integers a and s (1≤a,s≤10^8), representing a researcher that arrives after a minutes and stays for exactly s minutes.
Output
Output the maximum number of unlockings Penelope may save herself.
佩内洛普是新建立的超级计算机的管理员中的一员。 她的工作是分配工作站给到这里来运行他们的计算研究任务的研究人员。
佩内洛普非常懒惰,不喜欢为到达的研究者们解锁机器。 她可以从在她的办公桌远程解锁这些机器,但她并不觉得这卑贱的任务配得上她,所以她决定忽略安全指南偷偷懒。她可以直接地要求,研究者在他们离开时不用锁定自己的工作站,然后把未在使用且还在未锁定状态的工作站分配给新来的研究人员。 这样,她只需要为每一个工作站第一次被使用所属的研究员解锁工作站,这对佩内洛普的工作来说是一个巨大的改善。
不幸的是,如果一个工作站在未锁定且没被使用的状态下超过m分钟,会自动锁定自己,佩内洛普必须为使用它的下一个研究员再次打开它。 鉴于抵达和离开的研究人员的确切时间表,你可以告诉佩内洛普,要求研究者在离开时不锁定工作站最多可以使她节约多少次的解锁工作。你可以认为这儿总是有足够的可用工作站。
Input

一行两个整数n (1≤n≤300000) 研究员的数量n,以及 m (1≤m≤100000000) 工作站在未锁定且没被使用的状态下超过m分钟会自动锁定。
下面的n行,每一行两个整数a与s (1≤a,s≤100000000) 表示一个研究员在第a分钟时到达以及待了s分钟后离开。
Output

输出研究者在离开时不锁定工作站最多可以使她节约多少次解锁工作。
Sample Input

Sample Input 1

3 5

1 5

6 3

14 6

Sample Input 2

5 10

2 6

1 2

17 7

3 9

15 6
Sample Output

Sample Output 1

2

Sample Output 2

3

HINT

Source

NWERC2015还剩一个奇怪的计算几何题..不想写了..
其他题版切成功.
总体难度不算难,比SDOI要简单不少,里面比较难的题也就是跟弱省省选差不多吧
很多题都是一眼题.
写题解时候因为懒得写文字,直接贴了官方题解的图片…
这里写图片描述

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#define MAXN 300010
#define GET (ch>='0'&&ch<='9')
using namespace std;
int n,m,ans;
inline void in(int &x)
{
    char ch=getchar();x=0;
    while (!GET)    ch=getchar();
    while (GET) x=x*10+ch-'0',ch=getchar();
}
struct stuff    {   int l,r;    }s[MAXN];
inline bool cmp1(stuff a,stuff b)   {   return a.l<b.l; }
struct process
{
    int x;
    inline bool operator <(const process& a)const   {   return x>a.x;   }
};
priority_queue<process> heap;
int main()
{
    in(n);in(m);
    for (int i=1;i<=n;i++)  in(s[i].l),in(s[i].r),s[i].r+=s[i].l;
    sort(s+1,s+n+1,cmp1);heap.push((process){s[1].r+m});
    for (int i=2;i<=n;i++)
    {
        while (!heap.empty()&&heap.top().x<s[i].l)  heap.pop();
        int t=heap.top().x;
        if (t-m<=s[i].l&&s[i].l<=t) ans++,heap.pop();
        heap.push((process){s[i].r+m});
    }
    cout<<ans<<endl;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值