Pagini recente » Cod sursa (job #1829715) | Cod sursa (job #1090696) | Cod sursa (job #3139010) | Cod sursa (job #400055) | Cod sursa (job #2211003)
#include <fstream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <bitset>
#include <cassert>
#include <ctime>
#include <cstdlib>
#include <set>
#include <complex>
using namespace std;
const int SIZE = 1 << 10;
int pointer = SIZE;
char buffer[SIZE];
char Advance() {
if (pointer == SIZE) {
fread(buffer, 1, SIZE, stdin);
pointer = 0;
}
return buffer[pointer++];
}
int Read() {
int answer = 0;
char ch = Advance();
while (!isdigit(ch))
ch = Advance();
while (isdigit(ch)) {
answer = answer * 10 + ch - '0';
ch = Advance();
}
return answer;
}
const int nmax=500000;
int n,k,v[nmax+5];
int deq[nmax+5],st=1,dr=0;
int best=-1e9,st_sol,dr_sol;
int main()
{
freopen("secventa.in","r",stdin);
freopen("secventa.out","w",stdout);
n=Read();
k=Read();
for(int i=1;i<=n;i++)
{
v[i]=Read();
if(st<=dr and i-deq[st]+1>k)
st++;
while(st<=dr and v[i]<=v[deq[dr]])
dr--;
deq[++dr]=i;
if(i>=k and v[deq[st]]>best)
{
best=v[deq[st]];
st_sol=i-k+1;
dr_sol=i;
}
}
printf("%d %d %d",st_sol,dr_sol,best);
return 0;
}