Novice to understand (understand there may be the wrong place, please advise, hehe)
#include<stdio.h> #include<string.h> #include<math.h> #include<iostream> #include<algorithm> #include<queue> #include<stack> #define M 100005 using namespace std; int a,n,m,k,i,p[M],mintail,minhead,maxtail,maxhead,ans,trmp,last,last2; struct PP{ int viluee; //值 (单词打错了不要建议) int markee; //标号 }maxque[M],minque[M]; int main(){ while(~scanf("%d%d%d",&n,&m,&k)) { //清零 ans=0; maxhead=0;maxtail=0;minhead=0;mintail=0; last=last2=0; memset(minque,0,sizeof(minque));memset(maxque,0,sizeof(maxque)); //输入 for(i=1;i<=n;i++) scanf("%d",&p[i]); for(i=1; I <= n-; I ++ ) { the while (maxhead <= maxtail && maxque [maxtail] .viluee <P [I]) maxtail--; // maintain maximum maxque [++ maxtail] .viluee = p [i]; maxque [ maxtail] .markee = I; the while (minhead <= mintail && MINQUE [mintail] .viluee> P [I]) mintail--; // maintain a minimum minque [++ mintail] .viluee = p [i]; minque [mintail] = .markee I; the while (maxque [maxhead] .viluee-MINQUE [minhead] .viluee> K) { IF (maxque [maxhead] .markee <= MINQUE [minhead] .markee) Last = maxque [maxhead ++] Markee.; // Last saved index j is the maximum value of the current maximum value - minimum most> K the else //Reference numerals, instead of the reference numeral maxhead ++, to let the rear J last2 = MINQUE [minhead ++] Markee;. // element includes an intake (maximum current i is the number of elements in at the tail) // particularly easy to mistake, gas death of me } IF (maxque [maxhead] .viluee-MINQUE [minhead] .viluee> = m) { ANS = max (ANS, I-max (Last, last2)); // make sure that the queue element has two } } the printf ( " % D \ n- " , ANS); } return 0 ; }