Pagini recente » Cod sursa (job #2950013) | Cod sursa (job #1881505) | Cod sursa (job #1073734) | Cod sursa (job #306704) | Cod sursa (job #1370154)
#include <fstream>
#include <iostream>
#include <vector>
int main()
{
std::ifstream fin("secv2.in");
std::ofstream fout("secv2.out");
int N, K;
fin >> N >> K;
std::vector<int> v(N);
for (auto &i : v)
fin >> i;
int start_idx = 0, end_idx = 0;
int current_max = v[0];
int max = current_max;
int max_start, max_end;
for (auto i = 1; i < N; ++i) {
while (end_idx - start_idx >= K && v[start_idx] <= 0) {
current_max -= v[start_idx];
start_idx++;
}
current_max += v[i];
++end_idx;
if (current_max > max) {
max = current_max;
max_start = start_idx;
max_end = end_idx;
}
}
fout << max_start + 1 << " " << max_end + 1 << " " << max << "\n";
return 0;
}