Pagini recente » Cod sursa (job #361221) | Cod sursa (job #2537095) | Cod sursa (job #2028920) | Cod sursa (job #356375) | Cod sursa (job #1642151)
#include <cstdio>
using namespace std;
int best[50005],n,k,x,lung[50005],i,max1,inmax,in,sf,sfmax;
int main()
{
freopen("secv2.in","r",stdin);
freopen("secv2.out","w",stdout);
scanf("%d%d",&n,&k);
lung [1]=1;
for(i=1;i<=n;i++)
{
scanf("%d",&x);
best[i]=x;
if(best[i-1]+best[i]>best[i])
{
best[i]=best[i-1]+best[i];
lung[i]=lung[i-1]+1;
}
else
if(i-1!=0)
if(best[i-1]+best[i]<best[i-1])
{
lung[i]=1;
best[i]=best[i-1];
in=i;
}
if(best[i]>max1&&lung[i]>=k)
{
max1=best[i];
inmax=in;
sfmax=i;
}
}
printf("%d %d %d",inmax+1,sfmax,max1);
return 0;
}