Pagini recente » Cod sursa (job #1852761) | Cod sursa (job #1797310) | Cod sursa (job #624658) | Cod sursa (job #1088701) | Cod sursa (job #2191474)
#include <fstream>
using namespace std;
ifstream cin("secv2.in");
ofstream cout("secv2.out");
int main()
{
long long int n,k,sum=0;
cin>>n>>k;
long long int vec[n];
for(int i=0; i<n; i++)
{
cin>>vec[i];
if(i<k)
sum+=vec[i];
}
long long int first=0,last=k-1,rf,rl,maxx=0,mij;
for(; last<n; )
{
//cout<<sum<<" "<<first<<" "<<last<<"!\n";
if(sum<1)
{
first++;
last=first+k-1;
sum=0;
for(int j=first; j<=last; j++)
sum+=vec[j];
}
else
{
if(sum>=maxx)
{
maxx=sum;
rf=first;
rl=last;
}
mij=sum/2;
if(mij<sum+vec[last+1])
{
last++;
sum+=vec[last];
}
else
{
first++;
last=first+k-1;
sum=0;
for(int j=first; j<=last; j++)
sum+=vec[j];
}
}
}
cout<<rf+1<<" "<<rl+1<<" "<<maxx;
return 0;
}