Pagini recente » Cod sursa (job #256921) | Cod sursa (job #2282491) | Cod sursa (job #542728) | Cod sursa (job #2201773) | Cod sursa (job #484980)
Cod sursa(job #484980)
#include <fstream>
#include <deque>
#include<vector>
using namespace std;
deque<pair<int,int> >Q;
int i,n,k,poz,maxim,a;
ifstream fi("secventa.in");
ofstream fo("secventa.out");
int main()
{
fi>>n>>k;
maxim=-int(2e9);
for(i=1;i<=n;i++)
{
fi>>a;
while(!Q.empty() and Q.back().first>=a)
Q.pop_back();
Q.push_back(make_pair(a,i));
if(i>=k) if(maxim<Q.front().first) maxim=Q.front().first, poz=i;
if(i>=k) if(Q.front().second<=i-k+1) Q.pop_front();
}
fo<<poz-k+1<<" "<<poz<<" "<<maxim<<"\n";
return 0;
}