Pagini recente » Cod sursa (job #2222373) | Cod sursa (job #2867454) | Cod sursa (job #2179353) | Cod sursa (job #1498591) | Cod sursa (job #1257132)
// Include
#include <fstream>
using namespace std;
// Constante
const int sz = (int)5e4+1;
const int oo = (1<<30)-1;
// Variabile
ifstream in("secv2.in");
ofstream out("secv2.out");
int num, len;
int sum[sz];
int currentLeft, currentRight;
int maxSum=-oo, maxLeft, maxRight;
// Main
int main()
{
in >> num >> len;
for(int i=1 ; i<=num ; ++i)
in >> sum[i], sum[i] += sum[i-1];
sum[0] = oo;
for(int i=len+1 ; i<=num ; ++i)
{
if(sum[i-len] < sum[currentLeft-1])
currentLeft = i-len;
currentRight = i;
if(sum[currentRight] - sum[currentLeft-1] > maxSum)
{
maxSum = sum[currentRight] - sum[currentLeft-1];
maxLeft = currentLeft;
maxRight = currentRight;
}
}
out << maxLeft << ' ' << maxRight << ' ' << maxSum << '\n';
in.close();
out.close();
return 0;
}