Pagini recente » Cod sursa (job #590834) | Cod sursa (job #2251473) | Cod sursa (job #2611789) | Cod sursa (job #2971823) | Cod sursa (job #2502626)
#include <bits/stdc++.h>
using namespace std;
int n,k,nr,poz,baza=-4000000,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<=k;++i) {
scanf("%d", &nr);
while(!chestie.empty() && chestie.back().second>nr)
chestie.pop_back();
chestie.push_back(make_pair(i,nr));
}
for(int i=k+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) {
if(chestie.front().second>baza)
baza=chestie.front().second,poz=chestie.front().first,poz1=i;
chestie.pop_front();
}
}
printf("%d %d %d", poz, poz1, baza);
return 0;
}