why i getting wrong ans and what is the output for cases n=11 bi=10,10,10,10,10,10,10,10,10,10,10

#include<stdio.h>
int sum,n,b[1000],i,t,j,c,k;
int main(){

//printf("enter test cases");
scanf("%d",&t);
printf("\n");
while(t>0){
	sum=0;
	k=0;
//	printf("enter no");
	scanf("%d",&n);
	printf("\n");
	for(i=0;i<n;i++){
	scanf("%d",&b[i]);
	sum=sum+b[i];
	if(b[i]==0){
		
		k=1;
	}
	}
	if(sum<100){
		printf("NO\n");
	}
	else {
		
		if(sum==100){
			
			printf("YES\n");
		}
		else{
			c=sum-100;
			j=c/10;
			j=j+1;
			
		if((c+j+k)<=n){
			printf("YES\n");	
		}
		else	
		printf("NO\n");	
		}
	}
	t--;
}

}

the answer for test case n = 11 and bi = 10,10,… will be YES but your program is giving NO.Because we can have bi’s like 9+(1/11). So summation bi = 11*(9+(1/11)) = 99 + 1 = 100. There is some problem with your logic where you do c = sum-100;j = c/10;j = j+1;.

1 Like