Pagini recente » Cod sursa (job #1906779) | Cod sursa (job #3277788) | Cod sursa (job #3241034) | Statistici FMI - Deresu Roberto (deresuroberto) | Cod sursa (job #2068550)
#include <iostream>
#include <climits>
#include <fstream>
using namespace std;
ifstream fin ("secv2.in");
ofstream fout ("secv2.out");
int n,k,i,x,maxx = INT_MIN,st,stf,drf;
long long s,stot;
int main()
{
fin >> n >> k;
for(i=1; i<=n; i++)
{
fin >> x;
if(s<0)
{
s=x;
st=i;
}
else
s=s+x;
if(s>maxx && i-st+1>=k)
{
stf=st;
drf=i;
maxx=s;
}
stot+=x;
}
if(k==n)
fout << 1 << " " << n << " " << stot;
else
{
fout << stf << " " << drf << " " << maxx ;
}
return 0;
}