Pagini recente » Cod sursa (job #2805153) | Cod sursa (job #2799260) | Cod sursa (job #1822671) | Cod sursa (job #1146842) | Cod sursa (job #1697408)
#include <fstream>
#include <cstdio>
#include <iostream>
#include <vector>
#include <deque>
#define NMAX 5000005
#define HMAX 100005
#define pb push_back
#define INF 0x3f3f3f3f
using namespace std;
typedef pair<int, int> pii;
//ifstream fin("secventa.in");
FILE* fin=fopen("secventa.in","r");
const unsigned maxb=30000192;
char buf[maxb];
unsigned ptr=maxb;
inline unsigned getInt(){
unsigned nr=0;
while(buf[ptr]<'0'||'9'<buf[ptr])
if(++ptr>=maxb)
fread(buf,maxb,1,fin),ptr=0;
while('0'<=buf[ptr]&&buf[ptr]<='9'){
nr=nr*10+buf[ptr]-'0';
if(++ptr>=maxb)
fread(buf,maxb,1,fin),ptr=0;
}
return nr;
}
ofstream fout("secventa.out");
int main() {
int n,k,i,val,valmax,st,dr;
n=getInt();
k=getInt();
deque<pii> dq;
valmax=-INF;
for(i=1;i<=n;++i) {
val=getInt();
while(!dq.empty() && dq.back().second>val) dq.pop_back();
dq.push_back({i,val});
if(dq.front().first<=i-k) dq.pop_front();
if(i>=k) {
if(dq.front().second > valmax) {
valmax=dq.front().second;
st=i-k+1;
dr=i;
}
}
}
fout<<st<<' '<<dr<<' '<<valmax;
return 0;
}