Pagini recente » Cod sursa (job #1780824) | Cod sursa (job #2007897) | Cod sursa (job #1028090) | Cod sursa (job #568034) | Cod sursa (job #483614)
Cod sursa(job #483614)
#include <fstream>
#include <deque>
using namespace std;
ifstream in("secventa.in");
ofstream out("secventa.out");
deque < pair <int,int> > Q;
int vmax=-99999,p,i,N,K,v;
int main()
{
in>>N>>K;
for(i=1;i<=N;i++)
{
in>>v;
while(!Q.empty()&&Q.back().first>=v)
Q.pop_back();
Q.push_back(make_pair(v,i));
if(Q.front().first>vmax&&i>=K)
vmax = Q.front().first,p = i;
while(!Q.empty()&&Q.front().second<=i-K+1)
Q.pop_front();
}
out<<p-K+1<<' ' <<p<<' '<<vmax;
return 0;
}