Pagini recente » Cod sursa (job #1196846) | Cod sursa (job #1467537) | Cod sursa (job #1824804) | Cod sursa (job #673650) | Cod sursa (job #2504848)
#include <bits/stdc++.h>
using namespace std;
int n,k,nr,maxim,l,poz1;
deque < pair <int,int> > chestie;
int main () {
freopen("secventa.in","r",stdin);
freopen("secventa.out","w",stdout);
scanf("%d%d", &n, &k);
for(int i=1;i<=n;++i) {
scanf("%d", &nr);
while(!chestie.empty() && chestie.back().second>nr)
chestie.pop_back();
chestie.push_back(make_pair(i,nr));
while(!chestie.empty() && i-chestie.front().first+1>k)
chestie.pop_front();
if(i-chestie.front().first+1==k) {
if(chestie.front().second>maxim)
l=k,poz1=chestie.front().first,maxim=chestie.front().second;
}
}
printf("%d %d %d", poz1, poz1+k-1, maxim);
return 0;
}