标签:
先上题目:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4100 Accepted Submission(s): 1341
1 #include <cstdio> 2 #include <cstring> 3 #include <queue> 4 #include <algorithm> 5 #define MAX 100002 6 using namespace std; 7 8 int a[MAX]; 9 10 deque<int> maxn,minn; 11 12 int main() 13 { 14 int n,m,k,f,ans; 15 // freopen("data.txt","r",stdin); 16 while(scanf("%d %d %d",&n,&k,&m)!=EOF){ 17 while(!maxn.empty()) maxn.pop_front(); 18 while(!minn.empty()) minn.pop_front(); 19 for(int i=0;i<n;i++) scanf("%d",&a[i]); 20 ans=0; 21 f=0; 22 for(int i=0;i<n;i++){ 23 while(!maxn.empty() && a[maxn.back()]<a[i]) maxn.pop_back(); 24 while(!minn.empty() && a[minn.back()]>a[i]) minn.pop_back(); 25 maxn.push_back(i); 26 minn.push_back(i); 27 while(!maxn.empty() && !minn.empty() && (a[maxn.front()]-a[minn.front()])>m){ 28 if(maxn.front() > minn.front()){ 29 f = minn.front(); 30 minn.pop_front(); 31 }else if(minn.front() > maxn.front()){ 32 f = maxn.front(); 33 maxn.pop_front(); 34 }else{ 35 f = maxn.front(); 36 maxn.pop_front(); 37 minn.pop_front(); 38 } 39 f++; 40 } 41 if(!maxn.empty() && !minn.empty() && (a[maxn.front()] - a[minn.front()])>=k){ 42 ans = max(i-f+1,ans); 43 } 44 } 45 printf("%d\n",ans); 46 } 47 return 0; 48 }
标签:
原文地址:http://www.cnblogs.com/sineatos/p/3870757.html