Pagini recente » Monitorul de evaluare | Cod sursa (job #1493538) | Cod sursa (job #1019024) | Cod sursa (job #343866) | Cod sursa (job #1864332)
#include <fstream>
#include <deque>
using namespace std;
ifstream fin("secventa.in");
ofstream fout("secventa.out");
int k,n,c;
int b=-30001;
deque < pair < int , int > > coada;
int main()
{
int i;
int x;
fin>>n>>k;
for(i=1;i<k;i++)
{
fin>>x;
coada.push_front(make_pair(x,i));
}
for(i=k;i<=n;i++)
{
fin>>x;
if(!coada.empty() && i-coada.back().second+1==k && coada.back().first>x && b<x)
{
b=x;
c=coada.back().second;
}
while(!coada.empty() && coada.front().first>x)
coada.pop_front();
coada.push_front(make_pair(x,i));
if(i-coada.back().second>=k)
coada.pop_back();
if(coada.back().first>b)
{
b=coada.back().first;
c=coada.back().second;
}
}
fout<<c<<' '<<c+k-1<<' '<<b;
fin.close();
fout.close();
return 0;
}