Pagini recente » Cod sursa (job #542378) | Cod sursa (job #1098033) | Cod sursa (job #2451532)
#include <fstream>
#define nmax 500000
using namespace std;
ifstream in("secventa.in");
ofstream out("secventa.out");
int N, K, A[nmax], Deque[nmax], maxim = -1;
int main(){
in >> N >> K;
for(int i = 1; i<=N; i++)
in >> A[i];
int Front = 1, Back = 0;
for(int i = 1; i<=N; i++){
while(Front <= Back && A[i] >= A[Deque[Back]] && Deque[Front] <= i - K) Back--;
Deque[++Back] = i;
}
while(Deque[Front] + K - 1 > N)
Front--;
out << Deque[Front] <<' '<<Deque[Front] + 2 <<' '<< A[Deque[Front]];
return 0;
}