Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
1.1 kB
5
Indexable
Never
#include<stdio.h>

long long int n,x;
long long int ary[500000];
long long int ans=0;

long long int stack[500000];
long long int point=0;

int main(){
	scanf("%lld%lld",&n,&x);
	for(int i=0;i<n;i++){
		scanf("%lld",&ary[i]);
		while(point>0 && ary[i]>=stack[point-1]){
			ans+=n-i;																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																										
			point--;
		}
		stack[point++]=x-ary[i];
	}
	printf("%lld\n",ans);
}