Cod sursa(job #1253414)

Utilizator LegionHagiu Stefan Legion Data 1 noiembrie 2014 11:33:08
Problema Secventa Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.06 kb
#include <fstream>
#include <deque>
#include <string>
#include <iostream>
using namespace std;
int numere[500000];
int main()
{
	ifstream in("secventa.in");
	ofstream out("secventa.out");
	int n, i, k, curent, j, a, b, minim = 90000, x = 1;
	bool negativ = false;
	string s;
	in >> n;
	in >> k;
	in.get();
	getline(in, s);
	for (i = 0; i < s.size(); i++)
	{
		if (s[i] >= '0'&&s[i] <= '9'){ numere[x] = numere[x] * 10 + s[i] - 48; }
		if (s[i] == ' '){
			if (negativ == true){
				numere[x] = -numere[x]; negativ = false;
			}
			x++;
		}
		if (s[i] == '-'){ negativ = true; }
	}
		curent = 30001;
		for (i = 1; i <= k; i++)
		{
			if (numere[i] < curent){ curent = numere[i]; }
		}
		minim = curent;
		a = 1;
		b = k;
		for (i = 2; i <= n - k + 1; i++)
		{
			if (curent == numere[i - 1])
			{
				curent = 30001;
				for (j = i; j <= i + k - 1; j++)
				{
					if (numere[j] < curent){ curent = numere[j]; }
				}
				if (curent>minim){ minim = curent; a = i; b = i + k - 1; }
			}
		}
		out << a << " " << b << " " << minim << "\n";
}