Cod sursa(job #2502626)

Utilizator 1chiriacOctavian Neculau 1chiriac Data 1 decembrie 2019 11:56:07
Problema Secventa Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.78 kb
#include <bits/stdc++.h>

using namespace std;
int n,k,nr,poz,baza=-4000000,poz1;
deque < pair <int,int> > chestie;
int main () {
	freopen("secventa.in","r",stdin);
	freopen("secventa.out","w",stdout);
	scanf("%d%d", &n, &k);
	for(int i=1;i<=k;++i) {
		scanf("%d", &nr);
		while(!chestie.empty() && chestie.back().second>nr)
			chestie.pop_back();
		chestie.push_back(make_pair(i,nr));
	}
	for(int i=k+1;i<=n;++i) {
		scanf("%d", &nr);
		while(!chestie.empty() && chestie.back().second>nr)
			chestie.pop_back();
		chestie.push_back(make_pair(i,nr));
		while(!chestie.empty() && i-chestie.front().first+1>=k) {
			if(chestie.front().second>baza)
				baza=chestie.front().second,poz=chestie.front().first,poz1=i;
			chestie.pop_front();
		}
	}
	printf("%d %d %d", poz, poz1, baza);
	return 0;
}