CF898D. Alarm Clock(贪心 双指针)

网友投稿 610 2022-10-30

CF898D. Alarm Clock(贪心 双指针)

CF898D. Alarm Clock(贪心 双指针)

// Problem: D. Alarm Clock// Contest: Codeforces - Codeforces Round #451 (Div. 2)// URL: Memory Limit: 256 MB// Time Limit: 2000 ms// // Powered by CP Editor (namespace std;typedef long long ll;typedef unsigned long long ull;typedef pairPLL;typedef pairPII;typedef pairPDD;#define I_int llinline ll read(){ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}#define read read()#define rep(i, a, b) for(int i=(a);i<=(b);++i)#define dep(i, a, b) for(int i=(a);i>=(b);--i)ll ksm(ll a,ll b,ll p){ll res=1;while(b){if(b&1)res=res*a%p;a=a*a%p;b>>=1;}return res;}const int maxn=4e5+7,maxm=1e6+7,mod=1e9+7;int n,m,k,a[maxn];bool vis[maxn];int main(){ n=read,m=read,k=read; rep(i,1,n) a[i]=read; sort(a+1,a+1+n); int ans=0; int l=1,r=1,now=0; while(r<=n){ now++; while(a[r]-a[l]>=m){ if(!vis[l]) now--; l++; } if(now>=k){ ans++,now--; vis[r]=1; } r++; } cout<

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:UNIS: Go编程语言中的字符串工具类公共架构
下一篇:一个用于查询和共享任何PostgreSQL数据库的React Web应用程序
相关文章

 发表评论

暂时没有评论,来抢沙发吧~