Pagini recente » Cod sursa (job #2847524) | Cod sursa (job #2805840) | Clasament 14_martie_simulare_oji_2024_clasele_11_12 | Cod sursa (job #301812) | Cod sursa (job #2707537)
#include <fstream>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const int NMAX = 5e4 + 5;
int a[NMAX];
int main()
{
ifstream fin("secv2.in");
ofstream fout("secv2.out");
ios_base::sync_with_stdio(0);
fin.tie(0);
fout.tie(0);
int n, k, stop, start, ind;
ll minx = 1000000000000000;
ll ans = -1000000000000000;
fin >> n >> k;
for (int i = 0; i < n; i++)
{
fin >> a[i];
a[i] += a[i-1];
if (i < k);
else
{
if (a[i-k] < minx)
{
minx = a[i-k];
ind = i - k;
}
if (a[i] - minx > ans)
{
ans = a[i] - minx;
start = ind + 1;
stop = i;
}
}
}
fout << start + 1 << " " << stop + 1 << " " << ans;
return 0;
}