Pagini recente » Cod sursa (job #1998796) | Cod sursa (job #1995488) | Cod sursa (job #889667) | Cod sursa (job #1505308) | Cod sursa (job #2266631)
#include <iostream>
#include <fstream>
#include <deque>
using namespace std;
ifstream fin("secventa.in");
ofstream fout("secventa.out");
deque <pair <long long, int> > D;
int n,k,mini=-30001,a,b;
void rezolva()
{
fin>>n>>k;
long long s=0,x;
fin>>x;
D.push_back(make_pair(x,1));
for(int i=2; i<=n-k+1; i++)
{
fin>>x;
if(!D.empty())
{
if(x<D.back().first)
D.push_back(make_pair(x,i));
else
{
while(!D.empty()&&D.back().first<=x)
D.pop_back();
D.push_back(make_pair(x,i));
}
}
else D.push_back(make_pair(x, i));
if(i-k>=D.front().second)
D.pop_front();
if(i>=k)
if(D.front().first>mini)
{
mini=D.front().first;
a=D.front().second;
b=a+k-1;
}
}
}
int main()
{
rezolva();
fout<<a<<" "<<b<<" "<<mini;
return 0;
}