Pagini recente » Cod sursa (job #1352927) | Cod sursa (job #2182113) | Cod sursa (job #2747046) | Cod sursa (job #1672471) | Cod sursa (job #7964)
Cod sursa(job #7964)
#include<fstream.h>
long int a[10000],n,k,i,sc,ic,pc,sf,max=-1000000000;
int main()
{
ifstream f("secv2.in");
ofstream g("secv2.out");
f>>n>>k;
for(i=1;i<=n;i++)
f>>a[i];
sc=a[1];
ic=pc=sf=1;
for(i=2;i<=n;i++)
{
if(sc>0)
sc=sc+a[i];
else
{
sc=a[i];
pc=i;
}
if(sc>max)
{
max=sc;
ic=pc;
sf=i;
}
}
if(sf-ic>=k)
g<<ic<<" "<<sf<<" "<<max;
return 0;
}