Pagini recente » Cod sursa (job #3199323) | Cod sursa (job #2609022) | Cod sursa (job #8823) | Cod sursa (job #1988161) | Cod sursa (job #1441210)
#include <deque>
#include <fstream>
using namespace std;
const int dmax = 500003;
deque < int > D;
int a[dmax];
int main(){
ifstream fin ("secventa.in");
ofstream fout ("secventa.out");
int N, K, start, end, worst = -dmax;
fin >> N >> K;
for (int i = 1; i <= N; i++)
fin >> a[i];
for (int i = 1; i <= N; i++){
while ( !D.empty() && a[i] >= a[D.back()]) D.pop_back();
D.push_back(i);
if (D.front() == i - K - 1 ) D.pop_front();
if (i + K - 1 <= N){
if (a[D.front()] > worst) worst = a[D.front()], start = D.front(), end = i + K - 1 ;
}
}
fout << start << " " << end << " " << worst;
return 0;
}