leetcode84// I cant understand why code cant pass. I can compile this code correctly on dev c++
int stack[100000],index[100000];
int top=0;
int *p=⊤
int pop(int m,int *p,int max){
	int sum;
	int top=*p;
	int cover=index[top]+1;
	while (stack[top]>=m){
		sum=stack[top]*(cover-index[top-1]-1);
		if (sum>max) max=sum;
		top--;	
	}
	*p=top;
	return max;
}


void push(int data){
	top++;
	stack[top]=data;
}
int main(){
	int n,m;
	while(scanf("%d",&n)!=EOF){
		stack[0]=-1; index[0]=-1;
		top=0;
		int max=0;
		for (int i=0;i<n;i++){
			scanf("%d",&m);
			if (stack[top]>=m){ 
				max=pop(m,&top,max);
			}
			push(m);
			index[top]=i;
		}
		max=pop(0,&top,max);
			
		printf("%d\n",max);
	}
	return 0;
}
Comments (1)