|
|
back to boardTest case 1 My code is : #include<iostream> #include<stdio.h> #include<algorithm> using namespace std; struct slot{ int start; int stop; }; bool order1(const slot &lhs,const slot & rhs) { return lhs.stop<rhs.stop; } bool order2(const slot &lhs,const slot & rhs) { return lhs.start<rhs.start; } int main() { int timemax,timemin; long n,i,j,temp,dp[30002],max; slot a[100001]; dp[0]=0; scanf("%ld",&n); for(i=0;i<n;i++) scanf("%d%d",&a[i].start,&a[i].stop); sort(a,a+n,order2); timemin=a[0].start; stable_sort(a,a+n,order1); timemax=a[n-1].stop; for(i=0;i<=timemin;i++) dp[i]=0; for(i=timemin+1;i<=timemax;i++) { max=dp[i-1]; while(a[j].stop<i && j<n) j++; while(a[j].stop==i) { if(a[j].start-1>=0) temp=1+dp[a[j].start-1]; else temp=1; if(temp>max) max=temp; j++; if(j==n) break; } dp[i]=max; }
printf("%ld\n",dp[timemax]); } I dont know why I am getting wrong answer on test case 1 and runtime error on Ideone.com |
|
|