Cod sursa(job #2112980)

Utilizator marcudanfDaniel Marcu marcudanf Data 24 ianuarie 2018 00:58:03
Problema Secventa Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstring>

using namespace std;

int n, k, pos, Max=-2e9;

ifstream fin("secventa.in");
ofstream fout("secventa.out");

int v[500005];
string S;

int main(){
	char c;
	fin >> n >> k >> noskipws >> c;
	getline(fin ,S);
	stringstream sin(S);
	for(int i = 1; i <= n; i++)
		sin >> v[i];
	for(int i = 1; i <= n - k + 1; i++){
		int Min = 64000, Pos;
		for(int j = i; j < i + k ; j++)
			if(Min > v[j])
				Min = v[j], Pos = j;
		if(Max < Min)
			Max = Min, pos = Pos;
	}
	fout << pos << ' ' << pos + k - 1 << ' ' << Max;
	return 0;
}