Buildings !

There are n buildings in a row. The height of the i-th building is hi​. You have ৳k. It is the amoun…

Click here to read the complete problem statement.


If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.

#include <stdio.h>

int main() {
	int n,k,b[1000], max=0,min=100000, remain;
	scanf("%d%d", &n,&k);
	for(int i=0;i<n;i++){scanf("%d",&b[i]);}
	for(int i=0; i<n;i++){
		if(b[i]>max){
			max = b[i];
		}
		if(b[i]<min){
			min = b[i];
		}
	}

	remain = max - min;
	//printf("%d",remain+min);

	if(n>1){
		printf("%d",remain+min);
		
	}else if(n==1){
		printf("%d",remain+min+k);
	}
	return 0;
}

-----> why I am getting runtime error? how to solve this?

@Fariha.Brotecs Please check the input specification (especially the constraints on n). And check the size of the array b in your code.