Pagini recente » Cod sursa (job #2282575) | Cod sursa (job #280717) | Cod sursa (job #453747) | Cod sursa (job #958510) | Cod sursa (job #480906)
Cod sursa(job #480906)
#include<fstream>
#include<iostream>
#include<deque>
using namespace std;
int main()
{
int N,K;
long x,max=-30001;
fstream fin("secventa.in", fstream::in);
fstream fout("secventa.out", fstream::out);
deque<pair<long,long> > deq;
pair<long, long> pr;
fin>>N>>K;
//cout<<N<<" "<<K<<endl;
for(int i=1; i<=N; ++i)
{
fin>>x;
while(!deq.empty() && deq.back().second>=x)
deq.pop_back();
deq.push_back(make_pair(i,x));
//cout<<"pos "<<deq.back().first<<" "<<i-K<<endl;
while(!deq.empty() && deq.front().first<=i-K)
{
//cout<<"doing"<<endl;
deq.pop_front();
}
if(!deq.empty() && deq.front().second>max && i>=K)
{
max=deq.front().second;
pr=deq.front();
//cout<<max<<" ";
}
}
fout<<pr.first<<" "<<pr.first+K-1<<" "<<pr.second<<endl;
fin.close();
fout.close();
return 0;
}