Advertisement
lily09290110

b159 zerojude

Jan 31st, 2015
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.81 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. int cmp(const void *a,const void *b)
  4. {
  5.     int x=*(int *)a;
  6.     int y=*(int *)b;
  7.     return (x<y?-1:x>y?1:0);
  8. }
  9. int main(i)
  10. {
  11.     int limt,n,number[30005],count=0;
  12.     int lef_flag,right_flag;
  13.     while(~scanf("%d",&limt))
  14.     {
  15.         count=0;
  16.         for(scanf("%d",&n),i=0;i<n;i++)scanf("%d",&number[i]);
  17.         qsort(number,i,4,cmp);
  18.         lef_flag=0;right_flag=i-1;
  19.         while(right_flag>=lef_flag)
  20.         {
  21.             if((number[lef_flag]+number[right_flag])>limt)
  22.             {
  23.                 count++;
  24.                 right_flag--;
  25.             }
  26.             else
  27.             {
  28.                 count++;
  29.                 lef_flag++;
  30.                 right_flag--;
  31.             }
  32.         }
  33.         printf("%d\n",count);  
  34.     }
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement