Cod sursa(job #370481)
Utilizator | Savu Victor Gabriel undog | Data | 1 decembrie 2009 13:42:33 |
---|---|---|---|
Problema | Secventa | Scor | 80 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.5 kb |
#include <cstdio>
#include <deque>
int v[500000];
int main(){
freopen("secventa.in","rt",stdin);
freopen("secventa.out","wt",stdout);
std::deque<int> x;
int i,n,k;
int pos=15,max=-1000000;
scanf("%d%d",&n,&k);
for(i=0;i<n;i++){
scanf("%d",&v[i]);
while(!x.empty()&&v[i]<x.back())x.pop_back();
x.push_back(v[i]);
if(i>=k-1){
if(v[i-k]==x.front())
x.pop_front();
if(x.front()>max){
pos=i;
max=x.front();
}
}
}
printf("%d %d %d",pos+2-k,pos+1,max);
return 0;
}