首页 > 其他 > 详细

[SCOI2009]生日礼物

时间:2019-06-17 13:08:02      阅读:91      评论:0      收藏:0      [点我收藏+]

传送门:

#include <cstdlib>
#include <cstdio>
#include <algorithm>
using namespace std;
#define ll long long
#define re register
const int N=1e6+10;
inline void read(int &a)
{
    a=0;
    int d=1;
    char ch;
    while(ch=getchar(),ch>9||ch<0)
        if(ch==-)
            d=-1;
    a=ch^48;
    while(ch=getchar(),ch>=0&&ch<=9)
        a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
struct note
{
    int x,y;
}q[N];
int cnt;
inline bool cmp(note x,note y){return x.y<y.y;}
int p[65];
int main()
{
    int n,m;
    read(n);
    read(m);
    for(re int i=1;i<=m;i++)
    {
        int t;
        read(t);
        for(re int j=1;j<=t;j++)
        {
            read(q[++cnt].y);
            q[cnt].x=i;
        }
    }
    sort(q+1,q+1+n,cmp);
    int h,t;
    h=t=1;
    cnt=0;
    int ans=q[n].y-q[1].y;
    for(re int i=1;i<=n;i++)
    {
        if(!p[q[i].x])
            cnt++;
        p[q[i].x]=q[i].y;
        while(h<i&&q[h].y!=p[q[h].x])
            h++;
        if(cnt==m)
            ans=min(ans,q[i].y-q[h].y);
    }
    printf("%d",ans);
    return 0;
}

 

[SCOI2009]生日礼物

原文:https://www.cnblogs.com/acm1ruoji/p/11038928.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!