穿梭时间的画面的钟 从反方向 开始移动|

tmjyh09

园龄:3年2个月粉丝:1关注:3

P2107 小Z的AK计划 题解

题目传送门

分析

考虑一个贪心,由于 xi 呈线性排列,我们一定要保证去到的机房越多越好,所以将 x 排序,每次前往最近的机房,如果可以 AK 则 AK,累加答案。

代码实现

我相信我的解法一定有漏洞,欢迎各位 dalao 来 hack。

#include <bits/stdc++.h>
#define int long long
using namespace std;
inline int read(){
int x=0,f=0;char ch=getchar();
while(!isdigit(ch))f^=!(ch^45),ch=getchar();
while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
return f?-x:x;
}
int n,m,ans,pos;
int x[100005];
int t[100005];
signed main(){
n=read();m=read();
for(int i=1;i<=n;i++)x[i]=read(),t[i]=read();
sort(x+1,x+n+1);
for(int i=1;i<=n&&m;i++){
m-=abs(x[i]-pos);pos=x[i];
if(t[i]<=m)m-=t[i],ans++;
}
cout<<ans;
//system("pause");
}

本文作者:tmjyh09

本文链接:https://www.cnblogs.com/tmjyh09/p/15902028.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   tmjyh09  阅读(31)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起