Please tell me what's wrong???
Here is my code:
#include <cstdio>
#include <algorithm>
using namespace std;
#define MAXN 5607
int MIN(int a,int b)
{
return a<b?a:b;
}
typedef struct
{
int strenght,weight;
}turtle;
bool CMP(const turtle& a,const turtle& b)
{
if(a.strenght!=b.strenght)
{
return a.strenght>b.strenght;
}
return a.weight>b.weight;
}
turtle a[MAXN+10];
int l[MAXN+10],p[MAXN+10];
int main(){
//freopen("weights.in","r",stdin); freopen("weights.out","w",stdout);
int i,j,pos=0;
while(scanf("%d%d",&a[pos].weight,&a[pos].strenght)!=EOF)
{
pos++;
}
sort(a,a+pos,CMP);
int max,maxlen=0,k;
for(i=0;i<pos;++i)
{
max=0;
l[i]=1;
p[i]=a[i].strenght-a[i].weight;
for(j=0;j<i;++j)
{
if(a[i].weight<=p[j])
{
if(l[i]<=l[j]+1)
{
l[i]=l[j]+1;
k=MIN(p[j]-a[i].weight,a[i].strenght-a[i].weight);
if(k>max)
{
p[i]=k;
max=k;
}
}
}
}
if(l[i]>maxlen)maxlen=l[i];
}
printf("%d\n",maxlen);
return 0;
}

