Cod sursa(job #1218809)

Utilizator pavlov.ionPavlov Ion pavlov.ion Data 12 august 2014 16:34:24
Problema Secventa Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include<fstream>
#include<deque>
#define MAXN 500005
#define LL long long
using namespace std;
ifstream cin("secventa.in");
ofstream cout("secventa.out");
deque<int> q;
deque<int>::iterator it;
int N,K,A[MAXN],S=-100000,x,y;
int main() {
      int i;
	  cin>>N>>K;
	  for(i=1;i<=N;i++)
	              cin>>A[i];
      for(i=1;i<=N;i++) {
	  			while(q.size()>0 && A[i]<=A[q.back()]) q.pop_back();
	            q.push_back(i);
      if(q.front()==i-K) q.pop_front();         
	  if(A[q.front()]>S && i>=K) {
	  					S=A[q.front()];
	  					x=i-K+1;
	  					y=i;     }
	  }
cout<<x<<" "<<y<<" "<<S;
return 0;
}