Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
请教高手为什么TLE???#include "stdio.h" void main(){ long i,j,k,l,m,n,sum,max,t,t1; int p1[100010],d1[10010]; int is; while(scanf("%ld",&n)!=EOF){ sum=max=0; for(i=1;i<=n;i++) scanf("%d%d",&p1[i],&d1[i]); for(i=1;i<=n;i++){ for(j=1;j<=n-i;j++){ if(p1[j]<p1[j+1]){ t=p1[j]; p1[j]=p1[j+1]; p1[j+1]=t; t=d1[j]; d1[j]=d1[j+1]; d1[j+1]=t; } } } k=0;l=0; p1[0]=0;d1[0]=20000; while(k<n){ k++; if(d1[k]>l){ l++; sum=sum+p1[k]; } else{ m=l;is=1; while(d1[k]<=m){ if(d1[m]==m){ is=0; break; } m--; } if(is==1){ l++; sum=sum+p1[k]; t=p1[k];t1=d1[k]; for(j=l;j>m+1;j--){ d1[j]=d1[j-1]; p1[j]=p1[j-1]; } p1[j]=t; d1[j]=t1; } } } printf("%ld\n",sum); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator