Pagini recente » Cod sursa (job #488630) | Cod sursa (job #910468) | Cod sursa (job #2443152) | Cod sursa (job #576837) | Cod sursa (job #703541)
Cod sursa(job #703541)
#include<fstream>
#define Nmax 1000000000
using namespace std;
fstream f("secv2.in",ios::in);
fstream g("secv2.out",ios::out);
long long N,K,a[50005];
void gasire_secv()
{
long long i,j,x,y,max=-Nmax,S,L;
for(i=1;i<=N;i++)
{
L=K;
S=0;
for(j=i+K-1;j<=N;j++)
{
S=a[j]-a[i-1];
if(L>=K && max<S)
{
max=S;
x=i;
y=j;
}
L++;
}
}
g<<x<<" "<<y<<" "<<max;
}
void citire()
{
long long i,x;
f>>N>>K;
for(i=1;i<=N;i++)
{
f>>x;
a[i]+=a[i-1]+x;
}
}
int main()
{
citire();
gasire_secv();
f.close();
g.close();
return 0;
}