Cod sursa(job #2502806)
| Utilizator | Data | 1 decembrie 2019 17:03:37 | |
|---|---|---|---|
| Problema | Secventa | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.68 kb |
#include <fstream>
using namespace std;
int main()
{
ifstream fin ("secventa.in");
ofstream fout ("secventa.out");
int n,k,v[500001],d[500001],imax,bmax=-33333,p=1,u=1;
fin>>n>>k;
for (int i=1;i<=n;i++)
fin>>v[i];
d[u]=1;
for (int i=2;i<=n;i++)
{
while (v[d[u]]>=v[i]&&u>=p)
u--;
u++;
d[u]=i;
if (d[p]<=i-k)
p++;
if (i>=k)
if (v[d[p]]>bmax)
{
bmax=v[d[p]];
imax=d[p];
}
}
fout<<imax<<" "<<imax+k-1<<" "<<bmax;
fin.close();
fout.close();
return 0;
}
