Pagini recente » Cod sursa (job #446189) | Cod sursa (job #2102330) | Cod sursa (job #1029359) | Cod sursa (job #1030949) | Cod sursa (job #1088967)
#include <fstream>
using namespace std;
ifstream f("secventa.in");
ofstream g("secventa.out");
#define MAXN 500005
int N, K;
int deq[MAXN], front = 1, back = 0;
int sir[MAXN];
int main()
{
int i, inceput, sfarsit, maxim = -30005;
f >> N >> K;
for (i = 1; i <= N; ++i)
{
f >> sir[i];
while (front <= back && sir[deq[back]] > sir[i])
back--;
deq[++back] = i;
if (deq[front] == i - K)
front++;
if (i >= K && sir[deq[front]] > maxim)
maxim = sir[deq[front]], inceput = i - K + 1, sfarsit = i;
}
g << inceput << ' ' << sfarsit << ' ' << maxim;
return 0;
}