A year of Sichuan province election.
Enumerate each bead and look for all the kinds of beads in front of it and its maximum distance (this distance must include all the beads) and then update the answer.
For convenience, we sort the beads and form the list of links (also in reverse order).
However, this water problem ziliuziliu still not very good to think out. I don't know what's going on. This problem is actually quite simple ah.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define INF 0X7FFFFFFF
#define MAXN 1000050
#define MAXV 65
using namespace Std;
int CNT=0,NUM[MAXN],NEXT[MAXN],HEAD[MAXV];
int N,k,x,r,a[maxn],ans;
int find (int x)
{
int tmp=0;
for (int i=1;i<=k;i++)
{
while (Num[head[i]]>a[x])
{
Head[i]=next[head[i]];
if (head[i]==0) return 0;
}
if (Num[head[i]]<a[x])
Tmp=max (Tmp,a[x]-num[head[i]);
}
Ans=min (ANS,TMP);
return 1;
}
int main ()
{
Ans=inf;
memset (head,0,sizeof (head));
memset (Next,0,sizeof (next));
scanf ("%d%d", &n,&k);
for (int i=1;i<=k;i++)
{
scanf ("%d", &x);
for (int j=1;j<=x;j++)
{
scanf ("%d", &r);
A[++cnt]=r;
Num[cnt]=r;
Next[cnt]=head[i];
head[i]=cnt;
}
}
Sort (a+1,a+cnt+1);
for (int i=cnt;i>=1;i--)
{
if (a[i]!=a[i+1])
{
int Flag=find (i);
if (flag==0) break;
}
}
printf ("%d\n", ans);
return 0;
}
Bzoj 1293 Birthday Present