Pagini recente » Cod sursa (job #2022795) | Cod sursa (job #864042) | Istoria paginii utilizator/popovicimariagina | Cod sursa (job #1761740) | Cod sursa (job #2010650)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("secv2.in");
ofstream fout("secv2.out");
long long n, i, j, k, l, mx, best[50005], a, b, x;
int main () {
fin >> n >> k;
fin >> j;
best[1] = j;
mx = best[1];
a = 1; b = 1;
x = 1;
for (i = 2; i <= n; i++)
{
fin >> j;
if (best[i-1]+j > j)
best[i] = best[i-1]+j;
else
{
best[i] = j;
x = i;
}
if (best[i] > mx && i-x+1 >= k)
{
mx = best[i];
a = x; b = i;
}
}
fout << a << " " << b << " " << mx << "\n";
}