Pagini recente » Cod sursa (job #2406099) | Cod sursa (job #3225747) | Cod sursa (job #1924525) | Cod sursa (job #1123383) | Cod sursa (job #2585590)
#include <iostream>
#include <fstream>
using namespace std;
int A[100002];
int main()
{
ifstream fin("secv2.in");
ofstream fout("secv2.out");
int n,k;
fin>>n>>k;
for(int i=1; i<=n; i++)
{
fin>>A[i];
}
int Smax = -2000000000, S = -1, start=1, lmax=0,ulk=0,st,dr;
for(int i = 1 ; i <= n ; ++ i)
{
if(i>k)
{
ulk+=A[i];
ulk-=A[i-k];
if(S+A[i]<ulk)
{
start=i-k+1;
st=start;
}
S=max(ulk,S+A[i]);
if(S>Smax)
{
Smax=S;
dr=i;
}
}
else
{
S+=A[i];
ulk+=A[i];
}
}
fout <<st<<" "<<dr<<" "<< Smax ;
return 0;
}