Cod sursa(job #570204)
| Utilizator | Data | 2 aprilie 2011 18:31:04 | |
|---|---|---|---|
| Problema | Secventa | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.53 kb |
#include<fstream>
#define maxn 500010
using namespace std;
int v[maxn],q[maxn],n,k;
void citire()
{
int i;
ifstream in("secventa.in");
ofstream out("secventa.out");
in>>n>>k;
for (i=1;i<=n;i++)
in>>v[i];
}
int main()
{
int i,f=1,b=0,mn=-30011,poz;
citire();
for (i=1;i<=n;i++)
{
while (f<=b&&v[i]<=v[q[b]])
b--;
b++; q[b]=i;
if (q[f]==i-k)
f++;
if (i>=k&&mn<v[q[f]])
{
mn=v[q[f]];
poz=i;
}
}
ofstream out("secventa.out");
out<<poz-k+1<<" "<<poz<<" "<<mn<<'\n';
}
