Cod sursa(job #2658760)

Utilizator CyborgSquirrelJardan Andrei CyborgSquirrel Data 14 octombrie 2020 22:32:06
Problema Secventa Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <deque>

using namespace std;

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

int aw[500041];

int n, k;
deque<int> de;

struct wans{
	int lt, rt;
	int dio;
	bool valid = false;
};
wans ans;

int main(){
	// ios_base::sync_with_stdio(false);
	fin >> n >> k;
	for(int i = 1; i <= n; ++i){
		int a;fin>>a;
		aw[i] = a;
		
		if(!de.empty() && i-de.front() >= k)de.pop_front();
		while(!de.empty() && a<=aw[de.back()])de.pop_back();
		de.push_back(i);
		
		int y = aw[de.front()];
		if(i >= k && (!ans.valid || y > ans.dio)){
			ans.dio = y;
			ans.lt = i-k+1;
			ans.rt = i;
			ans.valid = true;
		}
	}
	fout << ans.lt << " " << ans.rt << " " << ans.dio;
	return 0;
}