Cod sursa(job #1253397)

Utilizator LegionHagiu Stefan Legion Data 1 noiembrie 2014 11:20:37
Problema Secventa Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.99 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 = numere[1];
	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";
}