Mai intai trebuie sa te autentifici.
Cod sursa(job #1607568)
Utilizator | Data | 21 februarie 2016 13:36:07 | |
---|---|---|---|
Problema | Secventa | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.78 kb |
#include <fstream>
#include <deque>
using namespace std;
ifstream fin("secventa.in");
ofstream fout("secventa.out");
deque<int> D;
int a[50001];
int n, k;
int main()
{
fin >> n >> k;
for ( int i = 1; i <= n; ++i)
{
fin >> a[i];
}
int vmax = 0, poz= 0;
for ( int i = 1; i <= n; ++i)
{
while ( !D.empty() && a[D.back()] >= a[i])
{
D.pop_back();
}
D.push_back(i);
if ( i- D.front() >= k)
{
D.pop_front();
}
if (i >= k && a[D.front()] > vmax )
{
vmax = a[D.front()];
poz = i;
}
}
fout << poz-k+1 << ' ' << poz << ' ' << vmax;
fin.close();
fout.close();
return 0;
}