Cod sursa(job #3226980)
Utilizator | Munteanu Mihnea Gabriel InformaticianInDevenire1 | Data | 23 aprilie 2024 16:19:50 |
---|---|---|---|
Problema | Secventa | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.64 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("secventa.in");
ofstream fout ("secventa.out");
deque <pair<int,int>> d;
int main()
{
int n,x,Max = -999999999,k,dr = 0;
fin >> n >> k;
for (int i=1;i<=n;++i){
fin >> x;
while (!d.empty() and i-d.front().second>=k) d.pop_front();
while (!d.empty() and d.back().first>=x) d.pop_back();
d.push_back({x,i});
if (i>=k){
if (Max<d.front().first){
Max = d.front().first;
dr = i;
}
}
}
fout << dr-k+1 << ' ' << dr << ' ' << Max;
return 0;
}