Pagini recente » Cod sursa (job #1993653) | Cod sursa (job #3150671) | Cod sursa (job #496089) | Cod sursa (job #112533) | Cod sursa (job #2707538)
#include <fstream>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const int NMAX = 5e4 + 5;
int a[NMAX+1];
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 = 0, start = 0, ind = 0;
ll minx = 1000000000000000LL;
ll ans = -1000000000000000LL;
fin >> n >> k;
for (int i = 1; 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 << " " << stop << " " << ans;
return 0;
}