Pagini recente » Cod sursa (job #2921824) | Cod sursa (job #1514934) | Cod sursa (job #1625833) | Cod sursa (job #153388) | Cod sursa (job #51608)
Cod sursa(job #51608)
#include <iostream.h>
#include <fstream.h>
fstream f("d://secv2.in",ios::in),g("d://secv2.out",ios::out);
long n,k,i,j,suma=-2000000000,ind1,ind2,cur;
int *v;
void SumaK(int i,int k)
{cur=0;
while(k) {cur+=v[i++]; k--;}
}
void inline comp()
{ if(cur>suma) {ind1=i; ind2=j; suma=cur;} }
int main()
{f>>n; f>>k;
v=new int[n+1];
for(i=1;i<=n;i++)
f>>v[i];
for(i=1;i<=n-k+1;i++) {SumaK(i,k); comp();
for(j=i+k;j<=n;j++) {cur+=v[j]; comp();}
}
delete v;
g<<ind1<<" "<<ind2<<" "<<suma; }