Cod sursa(job #1203050)
| Utilizator | Data | 30 iunie 2014 15:50:41 | |
|---|---|---|---|
| Problema | Secventa | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.87 kb |
#include <fstream>
#include <cmath>
#include <deque>
using namespace std;
ifstream cin("secventa.in");
ofstream cout("secventa.out");
deque <long> Dq;
long i,n,aux,k,A[500013],maxim(-999999),sol2,sol1(999999);
int main()
{
cin>>n>>k;
for (i=1;i<=n;++i){
cin>>A[i];
while(!Dq.empty() && A[i]<=A[Dq.back()]) Dq.pop_back();
Dq.push_back(i);
if (!Dq.empty() && i-k==Dq.front()) Dq.pop_front();
if (maxim<Dq.front() && i>=k){
maxim=Dq.front();
sol2=i;
sol1=i-k+1;
}
}
cout<<sol1<<" "<<sol2<<" "<<A[maxim];
return 0;
}
