Pagini recente » Cod sursa (job #628946) | Cod sursa (job #2049873) | Cod sursa (job #283347) | Cod sursa (job #2053595) | Cod sursa (job #2867969)
#include <iostream>
#include <deque>
#include <cstring>
#include <fstream>
using namespace std;
ifstream fin("secventa.in");
ofstream fout("secventa.out");
int a[500001];
int maxi=-5000001;
int n, k;
void citire(){
fin>>n>>k;
char c;
fin.get(c);
char s[500001];
fin.getline(s,500001);
int ind=0;
int semn=1;
int k=0;
while(ind<strlen(s)){
if(s[ind]=='-'){
semn=-1;
ind++;///sare peste semmn
}
else{
semn=1;
}
int nr=0;
while(isdigit(s[ind])){
nr=nr*10+(s[ind]-'0');
ind++;
}
nr*=semn;
a[++k]=nr;
while(s[ind]==' '){
ind++;
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
citire();
deque<int> Q(n+1);
int front =1;
int back=0;
int stop;
for(int i=1;i<=n;i++){
if(Q[front]==i-k){
front++;
}
while(front<=back && a[Q[back]]>=a[i]){
back--;
}
Q[++back]=i;
if(i>=k){
if(a[Q[front]]>maxi){
maxi=a[Q[front]];
stop=i;
}
}
}
fout << stop-k+1<<' '<<stop<<' '<<maxi;
return 0;
}