Pagini recente » Cod sursa (job #1680125) | Cod sursa (job #627049) | Cod sursa (job #1286109) | Cod sursa (job #2896613) | Cod sursa (job #2526837)
#include <bits/stdc++.h>
using namespace std;
ifstream ci("secventa.in");
ofstream cou("secventa.out");
int n,k,a[500005],nmax;
char s[500005];
int i, nr, j, semn;
deque<int>q;
void citire()
{
ci >> n >> k;
nr = j = 0;
semn = 1;
ci.get();
while(ci.get(s, 500000))
{
for(i = 0; s[i]; i++)
if(s[i] == '-') semn = -1;
else if(s[i] == ' ')
{
a[++j] = nr * semn;
nr = 0;
semn = 1;
}
else nr = nr * 10 +s[i] - '0';
}
if(j < n) a[++j] = nr * semn;
}
void rez()
{
int x,st,dr,i;
for(i=1; i<=k; i++)
{
x=a[i];
while(!q.empty()&&x<=a[q.back()] )
{
q.pop_back();
}
q.push_back(i);
}
nmax=a[q.front() ];
st=1;
dr=k;
for(i=k+1; i<=n; i++)
{
x=a[i];
while(!q.empty()&&x<=a[q.back()] )
{
q.pop_back();
}
q.push_back(i);
if(q.back()-q.front()>=k )
{
q.pop_front();
}
// cou<<i<<" "<<x<<" "<<q.front()<< " "<<q.back()<<"\n";
if(nmax<a[q.front()] )
{
nmax=a[q.front()];
dr=i;
st=i-k+1;
}
}
cou<<st<<" "<<dr<<" "<<nmax;
}
int main()
{
citire();
rez();
return 0;
}