Cod sursa(job #769636)

Utilizator lily3Moldovan Liliana lily3 Data 20 iulie 2012 12:31:54
Problema Cutii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.95 kb
#include<fstream>
#include<algorithm>
using namespace std;

int i,j,n,m,l[3501],t,max1,rez,p[3501],best[3501],poz,nr;
int x,y,z,a[3501],b[3501];
int compara(int i,int poz)
{
    if(a[i]<a[poz]&&b[i]<b[poz])
	    return 1;
    return 0;
}
int cauta(int poz)
{
    int mij,st=0,dr=nr;
    mij=(st+dr)/2;
    while(st<=dr)
    {
		if(compara(mij,poz)&&!compara(mij+1,poz))
		return mij;
	    else
		if(compara(mij+1,poz))
			st=mij+1,mij=(st+dr)/2;
		else
			dr=mij-1,mij=(st+dr)/2;
    }
    return nr;
}
int main()
{
    freopen("cutii.in","r",stdin);
    freopen("cutii.out","w",stdout);
    scanf("%d%d",&n,&t);
    while(t--)
    {
	for(i=1;i<=n;++i)
		scanf("%d%d%d",&x,&y,&z),a[x]=y,b[x]=z;
		nr=best[1]=l[1]=1;
	    l[0]=0;
	    rez=1;
	    for(i=2;i<=n;++i)
	    {
		    poz=cauta(i);
		    best[i]=poz+1;
		    p[i]=l[poz];
		    l[poz+1]=i;
		    if(nr<poz+1)
			nr=poz+1;
		    if(rez<best[i])
			   rez=best[i];
	    }
	printf("%d\n",rez);
    }
	return 0;
}