12.17省选模拟t1 生日礼物


题目

链接:https://xjoi.net/contest/3538/problem/1

另见SCOI2009 生日礼物

分析

显然是个双指针,然后就没了。

代码

#include
using namespace std;
template 
inline void read(T &x){
    x=0;char ch=getchar();bool f=false;
    while(!isdigit(ch)){if(ch=='-'){f=true;}ch=getchar();}
    while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    x=f?-x:x;
    return ;
}
template 
inline void write(T x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10^48);
    return ;
}
const int N=1000005;
int n,k,op,idx,cnt[N],now,ans=0x3f3f3f3f,hh,tt=-1,que[N];
struct node{int x,id;}a[N];
inline bool cmp(node x,node y){return x.x1) cnt[a[que[hh++]].id]--;
        if(now==k) ans=min(ans,a[i].x-a[que[hh]].x);
    }
    write(ans);
    return 0;
}