Pagini recente » Cod sursa (job #1773359) | Cod sursa (job #362479) | Istoria paginii utilizator/antonio.salaru | Cod sursa (job #403976) | Cod sursa (job #2045948)
/*#include <bits/stdc++.h>
using namespace std;
int n,k,c[55][55],a[55][55];
int Cerinta1()
{
int i,j;
///citire
fin>>i>>j;
fin>>n>>k;
for(int i=1;i<=k;i++)
{
}
}
int main()
{
fout<<Cerinta1();
}*/
#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;
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);//cout<<x<<" ";
cout<<q.front()<<" ";
if (maxim<q.front())
{
maxim=q.front();
st=i-k;
dr=i;
}
Pop();
}
fout<<st<<" "<<dr<<" "<<maxim<<"\n";
return 0;
}