Pagini recente » Cod sursa (job #730585) | Cod sursa (job #2625224) | Cod sursa (job #2950065) | Cod sursa (job #2257661) | Cod sursa (job #1642163)
#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]<best[i-1]+x)
{
best[i]=best[i-1]+x;
lung[i]=lung[i-1]+1;
}
else
if(i-1!=0)
{
if(best[i]>best[i-1]+x)
{
in=i;
lung[i]=1;
}
}
else
if(best[i]==best[i-1]+x)
{
in=i;
lung[i]=1;
}
if(best[i]>max1&&lung[i]>=k)
{
max1=best[i];
sfmax=i;
inmax=in;
}
}
printf("%d %d %d",inmax,sfmax,max1);
return 0;
}