Pagini recente » Cod sursa (job #3327199) | Cod sursa (job #464303) | Cod sursa (job #1947342) | Cod sursa (job #1755846) | Cod sursa (job #3312277)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("secv2.in");
ofstream fout("secv2.out");
const int DIM = 5e4 + 1;
long long n, k;
long long cnt, maxEnd, ans;
int ip, is;
int a[DIM];
int main()
{
fin >> n >> k;
for (int i = 1; i <= n; ++i)
fin >> a[i];
ip = is = cnt = 0;
for (int i = 1; i <= n; ++i)
{
maxEnd += a[i];
cnt++;
if (maxEnd >= 0)
{
if (cnt >= k && maxEnd > ans)
{
ans = maxEnd;
ip = i - cnt + 1;
is = i;
}
}
else
{
maxEnd = 0;
cnt = 0;
}
}
fout << ip << ' ' << is << ' ' << ans;
return 0;
}