Pagini recente » Cod sursa (job #1291429) | Cod sursa (job #1502582) | Cod sursa (job #1388274) | Cod sursa (job #1752898) | Cod sursa (job #46669)
Cod sursa(job #46669)
// Problema secventa
#include <stdio.h>
#define MAX 500001
#define MAXIM 32000
int sir[MAX];
int nr[MAX][2];
long ul, pr;
int main()
{
long n, k, i, q;
int max;
freopen( "secventa.in" , "rt", stdin );
scanf( "%ld %ld", &n, &k );
for( i=1; i<=n; i++ ) scanf( "%d", &sir[i] );
ul = 1; pr = 1;
q = 1;
nr[1][1] = sir[1];
nr[1][0] = 1;
max = -MAXIM;
for( i=2; i<=n; i++ )
{
while( ( ul > pr-1 ) && ( sir[i] < nr[ul][1] ) ) ul--;
ul++;
nr[ul][1] = sir[i];
nr[ul][0] = i;
if( i - nr[pr][0]+1 > k ) pr++;
// while( ( i - nr[pr][0]+1 > k ) && ( pr < ul+1 ) ) pr++;
if( ( pr < ul+1 ) && ( nr[pr][1] > max ) )
{
q = nr[pr][0];
max = nr[pr][1];
}
}
fclose( stdin );
freopen( "secventa.out", "wt", stdout );
printf( "%ld %ld %d\n", q, q+k-1, max );
fclose( stdout );
return 0;
}