Pagini recente » Cod sursa (job #574441) | Cod sursa (job #23146) | Cod sursa (job #2185934) | Cod sursa (job #2934929) | Cod sursa (job #2320331)
#include<fstream>
#include<vector>
std::ifstream f("secv2.in");
std::ofstream g("secv2.out");
int n, k, ok = 1, st_final, dr_final, st, dr;
long long v[50001], maxim = 0, maxim_final = 0,i;
int main()
{
f>>n>>k;
for(i=0;i<n;i++)
{
f>>v[i];
if(i<k)
maxim_final+=v[i];
}
dr_final = k - 1;
st_final = 0;
st = dr = 0;
maxim = v[0];
for(i=1;i<n;i++)
{
if (v[i] > maxim + v[i])
{
maxim = v[i];
st = dr = i;
}
else
{
maxim = maxim + v[i];
++dr;
}
if (dr - st + 1 >= k)
{
if (maxim > maxim_final)
{
maxim_final = maxim;
st_final = st;
dr_final = dr;
}
}
}
g<< st_final + 1 << " " << dr_final + 1 << " " << maxim_final;
}