Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- int count=0;
- int f(const void *a,const void *b){return (*(int *)a-*(int *)b);}
- int search(int arr[40],int fp,int temp)
- {
- int i,com=temp,record[fp+1],j,k=0;
- if(fp>=0)
- {
- for(i=fp-1;i>=0;i--)
- {
- if(arr[i]==0);
- else if(arr[i]==temp)
- {
- arr[i]=0;
- for(j=0;j<k;j++)
- {
- arr[record[j]]=0;
- }
- return 1;
- }
- else if(arr[i]<temp)
- {
- temp-=arr[i];
- record[k]=i;
- k++;
- }
- }
- return 1*search(arr,fp-1,com);
- }
- else return -1;
- }
- void desire(int arr[40],int fp,double a)
- {
- int temp,i;
- while(fp>=0)
- {
- if(arr[fp]==a||arr[fp]==0) fp--;
- else
- {
- temp=a-arr[fp];
- if(search(arr,fp,temp)==-1) {count++;break;}
- else fp--;
- }
- }
- }
- int main()
- {
- int n1,n,m,arr[40],i;
- double a;
- for(scanf("%d",&n1);n1>=1;n1--)
- {
- a=0;
- count=0;
- scanf("%d",&n);
- scanf("%d",&m);
- for(i=0;i<m;i++)
- {
- scanf("%d",&arr[i]);
- a+=arr[i];
- }
- a/=n;
- qsort(arr,m,4,f);
- if(arr[m-1]>a)count++;
- desire(arr,m-1,a);
- (count==0)?printf("1\n"):printf("0\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement