Pagini recente » Cod sursa (job #1324584) | Cod sursa (job #1341709) | Cod sursa (job #2560754) | Cod sursa (job #999697) | Cod sursa (job #2266722)
#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; 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;
b=i;
a=i-k+1;
}
}
}
int main()
{
rezolva();
fout<<a<<" "<<b<<" "<<mini;
return 0;
}