Pagini recente » Cod sursa (job #1237339) | Cod sursa (job #381064) | Cod sursa (job #1839313) | Cod sursa (job #2968667) | Cod sursa (job #1524768)
# include <fstream>
# include <climits>
using namespace std;
ifstream f("secventa.in");
ofstream g("secventa.out");
int a[5000000], prim, ulti, c[5000000], d, k, n, maxi=-INT_MAX, i;
char sir[5000000];
void citire();
int main()
{
int semn, index=0;
f>>n>>k;
f.getline (sir, 5000000, EOF);
for (i=0; sir[i]; i++)
{
semn=1;
if (sir[i]=='-')
{
semn=-1;
i++;
}
if (isdigit(sir[i]))
{
++index;
for (; isdigit(sir[i]); i++)
a[index]=a[index]*10+sir[i]-'0';
a[index]*=semn;
}
}
int prim=1; ulti=0;
for (i=1; i<=n; i++)
{
while (prim<=ulti && a[i]<a[c[ulti]])
ulti--;
c[++ulti]=i;
if (c[prim]<=i-k)
prim++;
if (i>=k)
{
if (a[c[prim]]>maxi)
{
maxi=a[c[prim]];
s=i-k+1;
d=i;
}
else
if (a[c[prim]]==maxi && prim<s)
{
s=i-k+1;
d=i;
}
}
}
g<<s<<' '<<d<<' '<<maxi;
return 0;
}