Pagini recente » Cod sursa (job #1246995) | Cod sursa (job #504769) | Cod sursa (job #1815854) | Cod sursa (job #2470305) | Cod sursa (job #2648155)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("secv2.in");
ofstream fout("secv2.out");
int n,i,j,s,k,st,dr,smax=INT_MIN,stmax,drmax,x;
int main()
{
fin>>n>>k;
st=dr=1;
for(i=1;i<=n;i++)
{
fin>>x;
if(dr-st+1>=k && smax<s)
{
smax=s;
stmax=st;
drmax=i-1;
}
if(x>s+x)
{
if(dr-st+1>=k && smax<s)
{
smax=s;
stmax=st;
drmax=dr-1;
}
s=x;
st=dr=i;
}
else
{
dr++;
s+=x;
}
}
if(n-st+1>=k && smax<s)
{
smax=s;
stmax=st;
drmax=n;
}
fout<<stmax<<" "<<drmax<<" "<<smax;
return 0;
}