Cod sursa(job #1457999)
| Utilizator | Data | 5 iulie 2015 15:06:46 | |
|---|---|---|---|
| Problema | Secventa | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.54 kb |
#include <fstream>
#include <queue>
using namespace std;
ifstream f("secventa.in");
ofstream g("secventa.out");
int n,k,i,a[500005],Max,start,stop;
deque<int> Q;
int main()
{
f>>n>>k;Max=-1;
for(i=1;i<=n;++i) f>>a[i];
for(i=1;i<=n;++i)
{
while(Q.size() && Q.front()<=i-k) Q.pop_front();
while(Q.size() && a[Q.back()]>a[i]) Q.pop_back();
if(a[Q.front()]>Max) Max=a[Q.front()], start=Q.front(), stop=i;
Q.push_back(i);
}
g<<start<<' '<<stop<<' '<<Max<<'\n';
f.close();g.close();
return 0;
}
