Pagini recente » Cod sursa (job #203508) | Cod sursa (job #2473976)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("secv2.in");
ofstream fout("secv2.out");
int n,k,i,l,lm,poz,pozm,a[50001];
long long sum,best[50001];
int main()
{
fin>>n>>k;
sum=-25000;
pozm=1;
poz=1;
for(i=1; i<=n; i++)
{
fin>>a[i];
if(best[i-1]+a[i]>a[i])best[i]=best[i-1]+a[i],l++;
else
{
poz=i;
l=0;
best[i]=a[i];
}
if(best[i]>sum&&l+1>=k)
{
pozm=poz;
lm=l;
sum=best[i];
}
}
fout<<pozm<<" "<<pozm+lm<<" "<<sum;
return 0;
}