Pagini recente » Istoria paginii utilizator/raraselz | Istoria paginii utilizator/minako2006 | Istoria paginii utilizator/igory | bruh | Cod sursa (job #826639)
Cod sursa(job #826639)
#include <cstdio>
#include <deque>
using namespace std;
deque <int> deq;
int a[500005];
long long n,i,k,baza,inceput,sfarsit;
char buffer[3500002];
int posinbuf = 0;
void citeste (int &x) {
char crt[10];
int rezultat = 0;
int semn = 1,startpos = 0;
int i = 0;
while (buffer[posinbuf] != ' ' && buffer[posinbuf] != 0) {
crt[i] = buffer[posinbuf];
i++;
posinbuf++;
}
posinbuf++;
if (crt[0] == '-') {
semn = -1;
startpos = 1;
}
for (int j = startpos; j<i;j++) rezultat = rezultat*10+crt[j]-'0';
x = rezultat*semn;
}
int main() {
freopen("secventa.in","r",stdin);
freopen("secventa.out","w",stdout);
scanf("%lld %lld",&n,&k);
getchar();
fgets(buffer,sizeof(buffer),stdin);
for (i=1;i<=k;i++) {
citeste(a[i]);
while (!deq.empty() && a[i] <= a[deq.back()]) deq.pop_back();
deq.push_back(i);
}
baza = a[deq.front()];
inceput = 1;
sfarsit = k;
for (i=k+1;i<=n;i++) {
citeste(a[i]);
while (!deq.empty() && a[i] <= a[deq.back()]) deq.pop_back();
deq.push_back(i);
if (deq.front() == i-k) deq.pop_front();
if (a[deq.front()] > baza) {
baza = a[deq.front()];
inceput = i-k+1;
sfarsit = i;
}
}
printf("%lld %lld %lld\n",inceput,sfarsit,baza);
return 0;
}