Pagini recente » Istoria paginii runda/splunge5 | Istoria paginii utilizator/normanpond8453 | Cod sursa (job #2471356)
#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;
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>=k)
{
pozm=poz;
lm=l;
sum=best[i];
}
}
fout<<pozm<<" "<<pozm+lm<<" "<<sum;
return 0;
}