Cod sursa(job #1144748)
| Utilizator | Data | 17 martie 2014 15:41:13 | |
|---|---|---|---|
| Problema | Secventa | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.54 kb |
#include<fstream>
using namespace std;
ifstream in("secventa.in");
ofstream out("secventa.out");
const int nmax = 500005;
int d[nmax], p = 1, q = 0, maxim, bestbeg, bestend, n, k, v[nmax];
int main(){
int player_unu=0;
in>>n>>k;
for(int i = 1; i<=n; i++)
{
in>>v[i];
while(v[d[q]]>=v[i] && p<=q)
q--;
q++;
d[q] = i;
if(i-d[p]>=k)
p++;
if(v[d[p]]>maxim)
{
bestbeg = i-k+1;
bestend = i;
maxim = v[d[p]];
}
}
out<<bestbeg<<" "<<bestend<<" "<<maxim<<'\n';
return player_unu;
}