Pagini recente » Cod sursa (job #1562276) | Cod sursa (job #12942) | Cod sursa (job #955097) | Cod sursa (job #1245371) | Cod sursa (job #1061566)
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <deque>
using namespace std;
int max1,j,n,k,sf,in,a[500005],i,ok;
deque <int> st;
char s[500005],c;
FILE *f,*g;
int main()
{f=fopen ("secventa.in","r");
g=fopen ("secventa.out","w");
fscanf (f,"%d%d",&n,&k);
fscanf (f,"%c",&c);
fgets (s,500001,f);
for (i=0;i<strlen (s);i++)
{ ok=0;
if (s[i]=='-') ok=1,i++;
if (isdigit (s[i]))
{ j++;
while (isdigit (s[i]))
{
a[j]=a[j]*10+(s[i]-'0');
i++;
}
if (ok==1) a[j]=0-a[j];
}
}
max1=-30009;
for (i=1;i<=n;i++)
{
while (!st.empty() && a[st.back()]>=a[i]) st.pop_back ();
st.push_back (i);
if (st.front ()<i-k+1) st.pop_front ();
if (i>=k && a[st.front ()]>max1)
{
max1=a[st.front ()];
in=i-k+1;
sf=i;
}
}
fprintf (g,"%d %d %d",in,sf,max1);
return 0;
}