Pagini recente » Profil dr_personality | Monitorul de evaluare | Profil dr_personality | Monitorul de evaluare | Cod sursa (job #3251330)
#include <fstream>
#include <deque>
using namespace std;
ifstream cin ("secventa.in");
ofstream cout ("secventa.out");
deque<int> bl;
int v[500001],inc,mini;
int main()
{
int n,k;
cin>>n>>k;
for(int i=1;i<=n;i++)
cin>>v[i];
for(int i=1;i<=k;i++){
while(!bl.empty() && v[i]<=v[bl.back()])
bl.pop_back();
bl.push_back(i);
}
mini=v[bl.front()];
inc=k;
for(int i=k+1;i<=n;i++){
while(!bl.empty() && v[i]<=v[bl.back()])
bl.pop_back();
if(!bl.empty() && i-bl.front()>=k)
bl.pop_front();
bl.push_back(i);
if(v[bl.front()]>mini){
mini=v[bl.front()];
inc=i;
}
}
cout<<inc-k+1<< ' ' <<inc<< ' ' <<mini;
return 0;
}