反正给了那么多时间,暴力就好。
Run Time: 0.04sec
Run Memory: 312KB
Code Length: 763Bytes
Submit Time: 2011-05-25 10:16:10
// Problem#: 1137
// Submission#: 777633
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include <iostream>
using namespace std;
int main()
{
int n, k;
int di[ 30000 ];
int i, j, max, min, keep, count = 1;
cin >> n >> k;
for ( i = 0; i < n; i++ )
cin >> di[ i ];
for ( i = 0; i < n - 1; i++ ) {
max = i;
min = i;
keep = 1;
for ( j = i + 1; j < n; j++ ) {
if ( di[ j ] > di[ max ] )
max = j;
if ( di[ j ] < di[ min ] )
min = j;
if ( di[ max ] - di[ min ] > k )
break;
else
keep++;
}
if ( keep > count )
count = keep;
i = ( max == j ? min: max );
}
cout << count << endl;
return 0;
}