Cod sursa(job #2061067)
| Utilizator | Data | 8 noiembrie 2017 21:50:25 | |
|---|---|---|---|
| Problema | Secventa | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.67 kb |
#include <iostream>
#include <fstream>
#include <deque>
using namespace std;
deque<pair<int,int>>d;
int main()
{
ifstream cin("secventa.in");
ofstream cout("secventa.out");
int n,i,k,st,dr,max=0,a;
cin>>n>>k;
for(i=1;i<=n;i++){
cin>>a;
while(!d.empty() && a<=d.back().first){
d.pop_back();
}
d.push_back(make_pair(a,i));
while(!d.empty() && d.front().second<=i-k){
d.pop_front();
}
if(d.front().first>max && i>=k){
max=d.front().first;
st=i-k+1;
dr=i;
}
}
cout<<st<<" "<<dr<<" "<<max;
return 0;
}
