Pagini recente » Cod sursa (job #434440) | Cod sursa (job #1948090) | Cod sursa (job #102509) | Cod sursa (job #2159344) | Cod sursa (job #1336137)
#include <fstream>
#include<deque>
using namespace std;
ifstream fin("secventa.in");
ofstream fout("secventa.out");
int s,n,k,i,aux,maxx,start;
deque<pair<int,int> >deq;
int main()
{
maxx=-(1<<30);
fin>>n>>k;
for(i=1;i<=n;++i)
{
fin>>aux;
while(!deq.empty()&&deq.back().first>=aux)
deq.pop_back();
if(!deq.empty()&&deq.front().second<=i-k)
deq.pop_front();
deq.push_back(make_pair(aux,i));
if(i>=k&&deq.front().first>maxx)
{
maxx=deq.front().first;
start=i;
}
}
fout<<start-k+1<<" "<<start<<" "<<maxx;
return 0;
}