题目地址:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1553
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; int main() { long long int a[10005],n,k; while( cin>>n>>k ) { long long int coun=1; for(int i=0; i<n; i++) scanf("%d",&a[i]); long long int sum=0; for(int i=0; i<n; i++) { int t=1; long long int max=a[i],min=a[i]; for(int j=i+1; j<n; j++) { if(a[j]>max) max=a[j]; if(a[j]<min) min=a[j]; t=j-i+1; if(max-min<=k) { coun = coun < t ? t : coun; } else break; } } cout<<coun<<endl; } return 0; }
时间: 2024-12-21 18:22:31