Pagini recente » Cod sursa (job #2097112) | Cod sursa (job #1527716) | Cod sursa (job #2875185) | Cod sursa (job #1054671) | Cod sursa (job #1147933)
#include <fstream>
#include <string.h>
#include <deque>
#define nMax 500001
using namespace std;
ifstream f("secventa.in");
ofstream g("secventa.out");
int n, k, bMax, a, b, v[nMax];
deque<int> deq;
char s[7 * nMax + 10];
void read(){
f>>n>>k;
f.get();
f.get(s, 7 * nMax + 10);
int i=n=1;
bool semn=true;
b=strlen(s);
s[b++]=' ';
s[b]='\0';
a=0;
for(int i=0;i<b;i++)
{
if(s[i]==' ')
{
a*=semn?1:-1, v[n++]=a, a=0, semn=true;
continue;
}
if(s[i]=='-')
{semn=false;continue;}
if(s[i]>='0' && s[i]<='9')
a*=10, a+=(s[i]-'0');
}
}
int main(){
read();
bMax=-30001;
for(int i=1;i<=n;i++){
while(deq.size() && v[deq.back()]>v[i])
deq.pop_back();
deq.push_back(i);
if(deq.front()==i-k)
deq.pop_front();
if(i>=k && v[deq.front()]>bMax)
bMax=v[deq.front()], a=i-k+1, b=i;
}
g<<a<<" "<<b<<" "<<bMax;
return 0;
}