Pagini recente » Cod sursa (job #2224947) | Cod sursa (job #2751849) | Cod sursa (job #2172147) | Cod sursa (job #2328145) | Cod sursa (job #1121687)
/// Craciun Catalin
/// Secv2
#include <fstream>
#include <iostream>
#define NMax 51000
using namespace std;
ifstream f("secv2.in");
ofstream g("secv2.out");
unsigned int n,k;
int A[NMax];
long long best;
unsigned int st, dr;
void afisare()
{
if (k==n)
{
long s=0;
for (unsigned int i=1; i<=n;i++)
s+=A[i];
g<<1<<' '<<n<<' '<<s<<'\n';
}
else
g<<st<<' '<<dr<<' '<<best<<'\n';
g.close();
}
void pd()
{
unsigned int auxSt;
long long suma=0;
unsigned int length=0;
bool found=false;
for (unsigned int i=1;i<=n;i++)
{
if (suma<0)
{
auxSt=i;
suma=A[i];
}
else
suma+=A[i];
if (i-auxSt+1>=k)
if (!found)
{
best=suma;
st=auxSt;
dr=i;
found=true;
}
else if (suma>best)
{
best=suma;
st=auxSt;
dr=i;
}
}
}
void citire()
{
f>>n>>k;
for (unsigned int i=1;i<=n;i++)
f>>A[i];
f.close();
}
int main()
{
citire();
pd();
afisare();
return 0;
}