Cod sursa(job #832514)

Utilizator andreea29Iorga Andreea andreea29 Data 10 decembrie 2012 20:26:51
Problema Secventa 2 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include<fstream>

#define Nmax 50010
#define INFI -0x3f3f3f3f

using namespace std;

int n, k, m, x, maxim, ind, ind1, s[Nmax];

int main()
{
	ifstream f("secv2.in");
	ofstream h("secv2.out");
	f >> n >> k;
	s[0] = 0;
	maxim = INFI;
	for (int i = 1; i <= n; ++i)
	{
		f >> x;
		s[i] = s[i - 1] + x;
		if (i >= k && s[i] >= maxim)
		{
			maxim = s[i];
			ind = i;
		}
	}
	f.close();
	maxim = INFI;
	for (int i = 1; i <= ind + 1 - k; ++i)
	{
		if (s[ind] - s[i - 1] >= maxim)
		{
			maxim = s[ind] - s[i - 1];
			ind1 = i;
		}
	}
	
	h << ind1 << " " << ind << " " << maxim << '\n';
	
	h.close();
	return 0;
}