Advertisement
nontawat1996

1080

Dec 25th, 2011
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.99 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int cmp(const void *a,const void *b)
  4. {
  5.     return (*(int*)a-*(int*)b);
  6. }
  7. int main()
  8. {
  9.     int n,wood[30001]= {0},i,j,end=1,total=0,max=-1;
  10.     scanf("%d",&n);
  11.     if(n<3)
  12.     {
  13.         printf("%d",n);
  14.         return 0;
  15.     }
  16.     for(i=0; i<n; i++) scanf("%d",&wood[i]);
  17.  
  18.     qsort(wood,n,sizeof(wood[0]),cmp);
  19.  
  20.     for(;;)
  21.     {
  22.         if(n-end<3) break;
  23.         for(i=n-end; i>=2; i--)
  24.         {
  25.             if(wood[i-2]+wood[i-1]<=wood[n-end])
  26.             {
  27.                 i--;
  28.                 total=(n-end)-i+1;
  29.                 if(total>max)
  30.                 {
  31.                     max=total;
  32.                     if(max>=(n-end))
  33.                     {
  34.                         printf("%d",max);
  35.                         return 0;
  36.                     }
  37.                 }
  38.                 break;
  39.             }
  40.         }
  41.         end++;
  42.     }
  43.  
  44.     //for(i=0;i<n;i++) printf("%d ",wood[i]);
  45.     printf("%d",max);
  46.  
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement