Pagini recente » Cod sursa (job #3220102) | Cod sursa (job #2402245) | Cod sursa (job #3163274) | Cod sursa (job #2825527) | Cod sursa (job #2426519)
#include <bits/stdc++.h>
#define NMAX 500005
using namespace std;
ifstream f ("secventa.in");
ofstream g ("secventa.out");
int n , k;
short x;
vector < short > a;
deque < int > d;
int main()
{
int inc = 0 , sf = 0 , baza = -NMAX , i;
a.push_back(0);
f >> n >> k;
for(i=1;i<=n;i++)
{
f >> x;
a.push_back(x);
}
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;
}