Pagini recente » Cod sursa (job #422089) | Cod sursa (job #2181328) | Cod sursa (job #359850) | Cod sursa (job #1806251) | Cod sursa (job #2044400)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("secventa.in");
ofstream fout("secventa.out");
deque<int>q;
queue<int>c;
void Push(int x)
{
c.push(x);
while(!q.empty()&&q.back()>x)
q.pop_back();
q.push_back(x);
}
void Pop()
{
int x=c.front();
if(x==q.front()) q.pop_front();
c.pop();
}
int main()
{
int n,k,x,i,maxim=-30005,st,dr;
fin>>n>>k;
for(i=1;i<=k;i++)
{
fin>>x;
Push(x);
}
if (maxim<q.front())
{
maxim=q.front();
st=i-k+1;
dr=i;
}
for(i=i;i<=n;i++)
{
fin>>x;
Push(x);
if (maxim<q.front())
{
maxim=q.front();
st=i-k+1;
dr=i;cout<<maxim<<" ";
}
Pop();
}
fout<<st<<" "<<dr<<" "<<maxim<<"\n";
return 0;
}