Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int cmp(const void *a,const void *b)
- {
- return (*(int*)a-*(int*)b);
- }
- int main()
- {
- int n,wood[30001]= {0},i,j,end=1,total=0,max=-1;
- scanf("%d",&n);
- if(n<3)
- {
- printf("%d",n);
- return 0;
- }
- for(i=0; i<n; i++) scanf("%d",&wood[i]);
- qsort(wood,n,sizeof(wood[0]),cmp);
- for(;;)
- {
- if(n-end<3) break;
- for(i=n-end; i>=2; i--)
- {
- if(wood[i-2]+wood[i-1]<=wood[n-end])
- {
- i--;
- total=(n-end)-i+1;
- if(total>max)
- {
- max=total;
- if(max>=(n-end))
- {
- printf("%d",max);
- return 0;
- }
- }
- break;
- }
- }
- end++;
- }
- //for(i=0;i<n;i++) printf("%d ",wood[i]);
- printf("%d",max);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement