Cod sursa(job #568902)
| Utilizator | Data | 31 martie 2011 20:03:56 | |
|---|---|---|---|
| Problema | Secventa | Scor | 50 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.51 kb |
#include<fstream>
using namespace std;
ifstream fi("secventa.in");
ofstream fo("secventa.out");
int n,i,k,minn,poz,first,last,v[500001],d[500001];
int main() {
fi>>n>>k;
fi>>v[1];
first=last=1;
d[1]=1;
minn=-32001;
for(int i=2;i<=n;++i){
fi>>v[i];
while(v[d[last]]>v[i]&&last)
last--;
d[++last]=i;
while(d[first]+k<=i)
first++;
if(minn<v[d[first]]&&i>=k){
poz=i;
minn=v[d[first]];
}
}
fo<<poz-k+1<<' '<<poz<<' '<<minn;
fi.close();
fo.close();
return 0;
}
