Pagini recente » Cod sursa (job #3285038) | Cod sursa (job #2353885) | Cod sursa (job #1887912) | Cod sursa (job #3154045) | Cod sursa (job #2426517)
#include <bits/stdc++.h>
#define NMAX 500005
using namespace std;
ifstream f ("secventa.in");
ofstream g ("secventa.out");
int n , k;
short a[NMAX];
deque < int > d;
int main()
{
int inc = 0 , sf = 0 , baza = -NMAX , i;
f >> n >> k;
for(i=1;i<=n;i++)
f >> a[i];
d.push_front(1);
for(i=1;i<=n;i++)
{
while(!d.empty() && a[i] <= a[d.back()])
d.pop_back();
d.push_back(i);
if(d.front() == i - k)
d.pop_front();
if(i >= k)
{
if(a[d.front()] > baza)
{
baza = a[d.front()];
inc = i - k + 1;
sf = i;
}
}
}
g << inc << ' ' << sf << ' ' << baza;
return 0;
}