Pagini recente » Cod sursa (job #2565926) | Cod sursa (job #2628927) | Cod sursa (job #2080110) | Cod sursa (job #1342147) | Cod sursa (job #2091532)
#include <fstream>
#define VectMax 50009
using namespace std;
int n,k,p,q,l,sc,scmax,V[VectMax],i,pf,qf;
bool gasit=false;
ifstream f("secv2.in");
ofstream g("secv2.out");
int main()
{
f>>n>>k;
for(i=1;i<=n;i++)
{
f>>V[i];
}
pf=0;
qf=0;
do
{
l=0;
sc=0;
p=1;
gasit=false;
q=1;
for(i=1;i<=n;i++)
{
sc+=V[q];
if(l==1)
{
sc-=V[p];
p++;
}
q++;
if(i==k)
l=1;
if(sc>scmax)
{
scmax=sc;
pf=p;
gasit=true;
qf=q;
}
}
if(sc>scmax)
{
scmax=sc;
pf=p;
qf=q;
gasit=true;
}
k++;
}
while(k<=n);
g<<pf<<" "<<qf<<" "<<scmax;
f.close();
g.close();
return 0;
}