Pagini recente » Cod sursa (job #1217478) | Cod sursa (job #899611) | Cod sursa (job #1739588) | Cod sursa (job #3211859) | Cod sursa (job #2666887)
#include <fstream>
using namespace std;
int main()
{
ifstream fin("secv2.in");
ofstream fout("secv2.out");
int n,k;
fin >> n >> k;
long long sc=0,smax=-9223372036854775807;
int drmax=1,st=1,stmax=1,lc=0;
for(int i=1;i<=n;i++)
{
int x;
fin >> x;
lc++;
if(sc<0)
{
sc=0;
st=i;
lc=0;
}
sc +=x;
if(sc>smax && lc>=k)
{
smax=sc;
drmax=i;
stmax=st;
}
}
fout << stmax << " " << drmax << " " << smax;
fout.flush();
return 0;
}